Skip to content

Commit 7e9e9dd

Browse files
OptimizeInstructions: Optimize (unsigned)x <= -1 ==> i32(1) even with side effects (#7436)
Fixes #7434
1 parent 4734c0e commit 7e9e9dd

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/passes/OptimizeInstructions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4025,10 +4025,10 @@ struct OptimizeInstructions
40254025
return right;
40264026
}
40274027
// (unsigned)x <= -1 ==> i32(1)
4028-
if (matches(curr, binary(LeU, pure(&left), ival(-1)))) {
4028+
if (matches(curr, binary(LeU, any(&left), ival(-1)))) {
40294029
right->value = Literal::makeOne(Type::i32);
40304030
right->type = Type::i32;
4031-
return right;
4031+
return getDroppedChildrenAndAppend(curr, right);
40324032
}
40334033
// (unsigned)x > -1 ==> i32(0)
40344034
if (matches(curr, binary(GtU, pure(&left), ival(-1)))) {

test/lit/passes/optimize-instructions-mvp.wast

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11132,9 +11132,29 @@
1113211132
;; CHECK-NEXT: (i32.const 1)
1113311133
;; CHECK-NEXT: )
1113411134
;; CHECK-NEXT: (drop
11135+
;; CHECK-NEXT: (block (result i32)
11136+
;; CHECK-NEXT: (drop
11137+
;; CHECK-NEXT: (i32.load
11138+
;; CHECK-NEXT: (i32.const 0)
11139+
;; CHECK-NEXT: )
11140+
;; CHECK-NEXT: )
11141+
;; CHECK-NEXT: (i32.const 1)
11142+
;; CHECK-NEXT: )
11143+
;; CHECK-NEXT: )
11144+
;; CHECK-NEXT: (drop
1113511145
;; CHECK-NEXT: (i32.const 1)
1113611146
;; CHECK-NEXT: )
1113711147
;; CHECK-NEXT: (drop
11148+
;; CHECK-NEXT: (block (result i32)
11149+
;; CHECK-NEXT: (drop
11150+
;; CHECK-NEXT: (i64.load
11151+
;; CHECK-NEXT: (i32.const 0)
11152+
;; CHECK-NEXT: )
11153+
;; CHECK-NEXT: )
11154+
;; CHECK-NEXT: (i32.const 1)
11155+
;; CHECK-NEXT: )
11156+
;; CHECK-NEXT: )
11157+
;; CHECK-NEXT: (drop
1113811158
;; CHECK-NEXT: (i32.lt_s
1113911159
;; CHECK-NEXT: (local.get $x)
1114011160
;; CHECK-NEXT: (i32.const 0)
@@ -11246,10 +11266,22 @@
1124611266
(local.get $x)
1124711267
(i32.const -1)
1124811268
))
11269+
(drop (i32.le_u
11270+
(i32.load
11271+
(i32.const 0)
11272+
)
11273+
(i32.const -1)
11274+
))
1124911275
(drop (i64.le_u
1125011276
(local.get $y)
1125111277
(i64.const -1)
1125211278
))
11279+
(drop (i64.le_u
11280+
(i64.load
11281+
(i32.const 0)
11282+
)
11283+
(i64.const -1)
11284+
))
1125311285
(drop (i32.le_s
1125411286
(local.get $x)
1125511287
(i32.const -1)

0 commit comments

Comments
 (0)