summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-04-11 15:57:32 +0000
committerSanjay Patel <spatel@rotateright.com>2017-04-11 15:57:32 +0000
commit28611acef913496941eac195b6500a292cad49f4 (patch)
treec6f5756e91742ec65dec09ed351fbe1c263f6cba
parenta53e6702d215b5825bebbe820f60af44693dcbe7 (diff)
downloadbcm5719-llvm-28611acef913496941eac195b6500a292cad49f4.tar.gz
bcm5719-llvm-28611acef913496941eac195b6500a292cad49f4.zip
revert r299851 - [InstCombine] fix matching of or-of-icmps constants (PR32524)
This is a candidate culprit for multiple bot fails, so reverting pending investigation. llvm-svn: 299955
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp28
-rw-r--r--llvm/test/Transforms/InstCombine/or.ll7
2 files changed, 16 insertions, 19 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index f6d51b945ae..9bbc5b281ab 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -807,7 +807,6 @@ 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 (LHS0 != RHS0)
@@ -826,14 +825,11 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
// Ensure that the larger constant is on the RHS.
bool ShouldSwap;
- 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.
+ if (CmpInst::isSigned(PredL) ||
+ (ICmpInst::isEquality(PredL) && CmpInst::isSigned(PredR)))
ShouldSwap = LHSC->getValue().sgt(RHSC->getValue());
- }
+ else
+ ShouldSwap = LHSC->getValue().ugt(RHSC->getValue());
if (ShouldSwap) {
std::swap(LHS, RHS);
@@ -881,6 +877,10 @@ 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(LHS0, AddC, LHS0->getName() + ".off");
@@ -1727,7 +1727,6 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
return Builder->CreateICmpULE(LHS0, LHSC);
}
- // FIXME: The code below is duplicated in FoldAndOfICmps.
// From here on, we only handle:
// (icmp1 A, C1) | (icmp2 A, C2) --> something simpler.
if (LHS0 != RHS0)
@@ -1746,14 +1745,11 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
// Ensure that the larger constant is on the RHS.
bool ShouldSwap;
- 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.
+ if (CmpInst::isSigned(PredL) ||
+ (ICmpInst::isEquality(PredL) && CmpInst::isSigned(PredR)))
ShouldSwap = LHSC->getValue().sgt(RHSC->getValue());
- }
+ else
+ ShouldSwap = LHSC->getValue().ugt(RHSC->getValue());
if (ShouldSwap) {
std::swap(LHS, RHS);
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index 64835ea9b83..2ac6f5b1104 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -223,9 +223,10 @@ define i1 @test19(i32 %A) {
define i1 @or_icmps_eq_diff1(i32 %x) {
; CHECK-LABEL: @or_icmps_eq_diff1(
-; CHECK-NEXT: [[X_OFF:%.*]] = add i32 %x, 1
-; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[X_OFF]], 2
-; CHECK-NEXT: ret i1 [[TMP1]]
+; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 %x, -1
+; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 %x, 0
+; CHECK-NEXT: [[LOGIC:%.*]] = or i1 [[CMP1]], [[CMP2]]
+; CHECK-NEXT: ret i1 [[LOGIC]]
;
%cmp1 = icmp eq i32 %x, -1
%cmp2 = icmp eq i32 %x, 0
OpenPOWER on IntegriCloud