summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-04-10 16:55:57 +0000
committerSanjay Patel <spatel@rotateright.com>2017-04-10 16:55:57 +0000
commit570e35c1570a21d98f8fce9378bfdbc36482968a (patch)
tree15599cb0b1001c628c817cabf905bc264733cecd /llvm/lib/Transforms
parent08126372e3363ce8ec27d345dbd6fb518be5f0b4 (diff)
downloadbcm5719-llvm-570e35c1570a21d98f8fce9378bfdbc36482968a.tar.gz
bcm5719-llvm-570e35c1570a21d98f8fce9378bfdbc36482968a.zip
[InstCombine] fix matching of or-of-icmps constants (PR32524)
Also, make the same change in and-of-icmps and remove a hack for detecting that case. Finally, add some FIXME comments because the code duplication here is awful. This should fix the remaining IR problem noted in: https://bugs.llvm.org/show_bug.cgi?id=32524 llvm-svn: 299851
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index fa2631c9535..3ed1c3af2ec 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -807,6 +807,7 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
}
}
+ // FIXME: The code below is duplicated in FoldOrOfICmps.
// From here on, we only handle:
// (icmp1 A, C1) & (icmp2 A, C2) --> something simpler.
if (Val != Val2)
@@ -825,11 +826,14 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
// Ensure that the larger constant is on the RHS.
bool ShouldSwap;
- if (CmpInst::isSigned(PredL) ||
- (ICmpInst::isEquality(PredL) && CmpInst::isSigned(PredR)))
- ShouldSwap = LHSC->getValue().sgt(RHSC->getValue());
- else
+ if (CmpInst::isUnsigned(PredL) || CmpInst::isUnsigned(PredR)) {
+ // We have an unsigned compare (possibly with an equality compare), so treat
+ // the constants as unsigned.
ShouldSwap = LHSC->getValue().ugt(RHSC->getValue());
+ } else {
+ // Equality transforms treat the constants as signed.
+ ShouldSwap = LHSC->getValue().sgt(RHSC->getValue());
+ }
if (ShouldSwap) {
std::swap(LHS, RHS);
@@ -877,10 +881,6 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
case ICmpInst::ICMP_SGT: // (X != 13 & X s> 15) -> X s> 15
return RHS;
case ICmpInst::ICMP_NE:
- // Special case to get the ordering right when the values wrap around
- // zero.
- if (LHSC->getValue() == 0 && RHSC->getValue().isAllOnesValue())
- std::swap(LHSC, RHSC);
if (LHSC == SubOne(RHSC)) { // (X != 13 & X != 14) -> X-13 >u 1
Constant *AddC = ConstantExpr::getNeg(LHSC);
Value *Add = Builder->CreateAdd(Val, AddC, Val->getName() + ".off");
@@ -1727,6 +1727,7 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
return Builder->CreateICmpULE(Val, LHSC);
}
+ // FIXME: The code below is duplicated in FoldAndOfICmps.
// From here on, we only handle:
// (icmp1 A, C1) | (icmp2 A, C2) --> something simpler.
if (Val != Val2)
@@ -1745,11 +1746,14 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
// Ensure that the larger constant is on the RHS.
bool ShouldSwap;
- if (CmpInst::isSigned(PredL) ||
- (ICmpInst::isEquality(PredL) && CmpInst::isSigned(PredR)))
- ShouldSwap = LHSC->getValue().sgt(RHSC->getValue());
- else
+ if (CmpInst::isUnsigned(PredL) || CmpInst::isUnsigned(PredR)) {
+ // We have an unsigned compare (possibly with an equality compare), so treat
+ // the constants as unsigned.
ShouldSwap = LHSC->getValue().ugt(RHSC->getValue());
+ } else {
+ // Equality transforms treat the constants as signed.
+ ShouldSwap = LHSC->getValue().sgt(RHSC->getValue());
+ }
if (ShouldSwap) {
std::swap(LHS, RHS);
OpenPOWER on IntegriCloud