llvm.org GIT mirror llvm / df015f1
[WebAssembly] Fix fast-isel optimization of branch conditions. LLVM doesn't guarantee anything about the high bits of a register holding an i1 value at the IR level, so don't translate LLVM IR i1 values directly into WebAssembly conditional branch operands. WebAssembly's conditional branches do demand all 32 bits be valid. Fixes PR38019. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336138 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 2 years ago
2 changed file(s) with 49 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
418418 return getRegForValue(ICmp->getOperand(0));
419419 }
420420
421 if (BinaryOperator::isNot(V)) {
421 if (BinaryOperator::isNot(V) && V->getType()->isIntegerTy(32)) {
422422 Not = true;
423423 return getRegForValue(BinaryOperator::getNotArgument(V));
424424 }
0 ; RUN: llc < %s -fast-isel -asm-verbose=false | FileCheck %s
1
2 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
3 target triple = "wasm32-unknown-unknown"
4
5 ; Fast-isel uses a 32-bit xor with -1 to negate i1 values, because it doesn't
6 ; make any guarantees about the contents of the high bits of a register holding
7 ; an i1 value. Test that when we do a `br_if` or `br_unless` with what what an
8 ; i1 value in LLVM IR, that we only test the low bit.
9
10 ; CHECK: i32.xor
11 ; CHECK: i32.const $push[[L0:[0-9]+]]=, 1{{$}}
12 ; CHECK: i32.and $push[[L1:[0-9]+]]=, $pop{{[0-9]+}}, $pop[[L0]]{{$}}
13 ; CHECK: br_if 0, $pop[[L1]]{{$}}
14
15 ; CHECK: i32.xor
16 ; CHECK: i32.const $push[[L2:[0-9]+]]=, 1{{$}}
17 ; CHECK: i32.and $push[[L3:[0-9]+]]=, $pop{{[0-9]+}}, $pop[[L2]]{{$}}
18 ; CHECK: br_if 0, $pop[[L3]]{{$}}
19
20 define void @test() {
21 start:
22 %0 = call i32 @return_one()
23 br label %bb1
24
25 bb1:
26 %1 = icmp eq i32 %0, 1
27 %2 = xor i1 %1, true
28 br i1 %2, label %bb2, label %bb3
29
30 bb2:
31 call void @panic()
32 unreachable
33
34 bb3:
35 %3 = xor i1 %2, true
36 br i1 %3, label %bb4, label %bb5
37
38 bb4:
39 call void @panic()
40 unreachable
41
42 bb5:
43 ret void
44 }
45
46 declare i32 @return_one()
47 declare void @panic()