diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-01-27 02:43:28 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-01-27 02:43:28 +0000 |
commit | c761afd1d1db72fc7986f76f23fed1dd8a1a3ad7 (patch) | |
tree | 4f6f461338dc85b672c9bdb8b320d649595d35c3 /llvm/test | |
parent | 47de2140f7b2e094a03b3ab40c9ab3f4cc911677 (diff) | |
download | bcm5719-llvm-c761afd1d1db72fc7986f76f23fed1dd8a1a3ad7.tar.gz bcm5719-llvm-c761afd1d1db72fc7986f76f23fed1dd8a1a3ad7.zip |
[SimplifyCFG] Don't mistake icmp of and for a tree of comparisons
SimplifyCFG tries to turn complex branch conditions into a switch.
Some of it's logic attempts to reason about bitwise arithmetic produced
by InstCombine. InstCombine can turn things like (X == 2) || (X == 3)
into (X & 1) == 2 and so SimplifyCFG tries to detect when this occurs so
that it can produce a switch instruction.
However, the legality checking was not sufficient to determine whether
or not this had occured. Correctly check this case by requiring that
the right-hand side of the comparison be a power of two.
This fixes PR26323.
llvm-svn: 258904
Diffstat (limited to 'llvm/test')
-rw-r--r-- | llvm/test/Transforms/SimplifyCFG/switch_create.ll | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/test/Transforms/SimplifyCFG/switch_create.ll b/llvm/test/Transforms/SimplifyCFG/switch_create.ll index 490b7513a94..f895a9f0284 100644 --- a/llvm/test/Transforms/SimplifyCFG/switch_create.ll +++ b/llvm/test/Transforms/SimplifyCFG/switch_create.ll @@ -554,3 +554,28 @@ bb20: ; preds = %bb19, %bb8 ; CHECK: %arg.off = add i32 %arg, -8 ; CHECK: icmp ult i32 %arg.off, 11 } + +define void @PR26323(i1 %tobool23, i32 %tmp3) { +entry: + %tobool5 = icmp ne i32 %tmp3, 0 + %neg14 = and i32 %tmp3, -2 + %cmp17 = icmp ne i32 %neg14, -1 + %or.cond = and i1 %tobool5, %tobool23 + %or.cond1 = and i1 %cmp17, %or.cond + br i1 %or.cond1, label %if.end29, label %if.then27 + +if.then27: ; preds = %entry + call void @foo1() + unreachable + +if.end29: ; preds = %entry + ret void +} + +; CHECK-LABEL: define void @PR26323( +; CHECK: %tobool5 = icmp ne i32 %tmp3, 0 +; CHECK: %neg14 = and i32 %tmp3, -2 +; CHECK: %cmp17 = icmp ne i32 %neg14, -1 +; CHECK: %or.cond = and i1 %tobool5, %tobool23 +; CHECK: %or.cond1 = and i1 %cmp17, %or.cond +; CHECK: br i1 %or.cond1, label %if.end29, label %if.then27 |