Skip to content

Commit 2daf000

Browse files
committed
fix off-by-one in assertion in optimize-instructions
1 parent 557eca7 commit 2daf000

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/passes/OptimizeInstructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
453453
if ((count > 0 && count < 32 - bits) || (constSignBit && count == 0)) {
454454
// mixed or [zero upper const bits with sign bit set]; the compared values can never be identical, so
455455
// force something definitely impossible even after zext
456-
assert(bits < 31);
456+
assert(bits < 32);
457457
c->value = Literal(int32_t(0x80000000));
458458
// TODO: if no side effects, we can just replace it all with 1 or 0
459459
} else {

test/passes/optimize-instructions.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,4 +1993,17 @@
19931993
)
19941994
)
19951995
)
1996+
(func $sign-ext-1-and-ne (type $2) (result i32)
1997+
(select
1998+
(i32.ne
1999+
(i32.and
2000+
(call $sign-ext-1-and-ne)
2001+
(i32.const 2147483647)
2002+
)
2003+
(i32.const -2147483648)
2004+
)
2005+
(i32.const 2)
2006+
(i32.const 1)
2007+
)
2008+
)
19962009
)

test/passes/optimize-instructions.wast

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,4 +2417,20 @@
24172417
)
24182418
)
24192419
)
2420+
(func $sign-ext-1-and-ne (result i32)
2421+
(select
2422+
(i32.ne
2423+
(i32.const 1333788672)
2424+
(i32.shr_s
2425+
(i32.shl
2426+
(call $sign-ext-1-and-ne)
2427+
(i32.const 1)
2428+
)
2429+
(i32.const 1)
2430+
)
2431+
)
2432+
(i32.const 2)
2433+
(i32.const 1)
2434+
)
2435+
)
24202436
)

0 commit comments

Comments
 (0)