summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-01-27 02:43:28 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-01-27 02:43:28 +0000
commitc761afd1d1db72fc7986f76f23fed1dd8a1a3ad7 (patch)
tree4f6f461338dc85b672c9bdb8b320d649595d35c3 /llvm/lib
parent47de2140f7b2e094a03b3ab40c9ab3f4cc911677 (diff)
downloadbcm5719-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/lib')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index b6d87c22e43..57adcecbdfb 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -405,13 +405,14 @@ private:
ConstantInt *RHSC;
// Pattern match a special case
- // (x & ~2^x) == y --> x == y || x == y|2^x
+ // (x & ~2^z) == y --> x == y || x == y|2^z
// This undoes a transformation done by instcombine to fuse 2 compares.
if (ICI->getPredicate() == (isEQ ? ICmpInst::ICMP_EQ:ICmpInst::ICMP_NE)) {
if (match(ICI->getOperand(0),
m_And(m_Value(RHSVal), m_ConstantInt(RHSC)))) {
APInt Not = ~RHSC->getValue();
- if (Not.isPowerOf2()) {
+ if (Not.isPowerOf2() && C->getValue().isPowerOf2() &&
+ Not != C->getValue()) {
// If we already have a value for the switch, it has to match!
if(!setValueOnce(RHSVal))
return false;
OpenPOWER on IntegriCloud