Skip to content

Commit de8f782

Browse files
committed
Revert "Simplify (a % b) lt/ge (b-1) into (a % b) eq/ne (b-1) (llvm#72504)"
This reverts commit 01f4d40. Causes test failures.
1 parent 289999b commit de8f782

File tree

3 files changed

+0
-396
lines changed

3 files changed

+0
-396
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,30 +2528,6 @@ Instruction *InstCombinerImpl::foldICmpShrConstant(ICmpInst &Cmp,
25282528
Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
25292529
BinaryOperator *SRem,
25302530
const APInt &C) {
2531-
{
2532-
const APInt *C1;
2533-
ICmpInst::Predicate Pred = Cmp.getPredicate();
2534-
if ((match(SRem->getOperand(1), m_NonNegative(C1))) &&
2535-
((Pred == ICmpInst::ICMP_SLT && C == *C1 - 1) ||
2536-
(Pred == ICmpInst::ICMP_SGT && C == *C1 - 2) ||
2537-
(Pred == ICmpInst::ICMP_SGT && C == -*C1 + 1) ||
2538-
(Pred == ICmpInst::ICMP_SLT && C == -*C1 + 2))) {
2539-
// icmp slt (X s% C), (C - 1) --> icmp ne (X s% C), (C - 1), if C >= 0
2540-
// icmp sgt (X s% C), (C - 2) --> icmp eq (X s% C), (C - 1), if C >= 0
2541-
// icmp sgt (X s% C), (-C + 1) --> icmp ne (X s% C), (-C + 1), if C >= 0
2542-
// icmp slt (X s% C), (-C + 2) --> icmp eq (X s% C), (-C + 1), if C >= 0
2543-
return new ICmpInst(
2544-
((Pred == ICmpInst::ICMP_SLT && C == *C1 - 1) ||
2545-
(Pred == ICmpInst::ICMP_SGT && C == -*C1 + 1))
2546-
? ICmpInst::ICMP_NE
2547-
: ICmpInst::ICMP_EQ,
2548-
SRem,
2549-
ConstantInt::get(SRem->getType(), C == -*C1 + 1 || C == -*C1 + 2
2550-
? -*C1 + 1
2551-
: *C1 - 1));
2552-
}
2553-
}
2554-
25552531
// Match an 'is positive' or 'is negative' comparison of remainder by a
25562532
// constant power-of-2 value:
25572533
// (X % pow2C) sgt/slt 0
@@ -2599,23 +2575,6 @@ Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
25992575
return new ICmpInst(ICmpInst::ICMP_UGT, And, ConstantInt::get(Ty, SignMask));
26002576
}
26012577

2602-
Instruction *InstCombinerImpl::foldICmpURemConstant(ICmpInst &Cmp,
2603-
BinaryOperator *URem,
2604-
const APInt &C) {
2605-
const APInt *C1;
2606-
ICmpInst::Predicate Pred = Cmp.getPredicate();
2607-
if (match(URem->getOperand(1), m_APInt(C1)) &&
2608-
((Pred == ICmpInst::ICMP_ULT && C == *C1 - 1) ||
2609-
(Pred == ICmpInst::ICMP_UGT && C == *C1 - 2 && C.ugt(1)))) {
2610-
// icmp ult (X u% C), (C - 1) --> icmp ne (X u% C), (C - 1)
2611-
// icmp ugt (X u% C), (C - 2) --> icmp eq (X u% C), (C - 1), if C >u 1
2612-
return new ICmpInst(Pred == ICmpInst::ICMP_UGT ? ICmpInst::ICMP_EQ
2613-
: ICmpInst::ICMP_NE,
2614-
URem, ConstantInt::get(URem->getType(), *C1 - 1));
2615-
}
2616-
return nullptr;
2617-
}
2618-
26192578
/// Fold icmp (udiv X, Y), C.
26202579
Instruction *InstCombinerImpl::foldICmpUDivConstant(ICmpInst &Cmp,
26212580
BinaryOperator *UDiv,
@@ -3753,10 +3712,6 @@ Instruction *InstCombinerImpl::foldICmpBinOpWithConstant(ICmpInst &Cmp,
37533712
if (Instruction *I = foldICmpSRemConstant(Cmp, BO, C))
37543713
return I;
37553714
break;
3756-
case Instruction::URem:
3757-
if (Instruction *I = foldICmpURemConstant(Cmp, BO, C))
3758-
return I;
3759-
break;
37603715
case Instruction::UDiv:
37613716
if (Instruction *I = foldICmpUDivConstant(Cmp, BO, C))
37623717
return I;

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
676676
const APInt &C);
677677
Instruction *foldICmpSRemConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
678678
const APInt &C);
679-
Instruction *foldICmpURemConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
680-
const APInt &C);
681679
Instruction *foldICmpUDivConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
682680
const APInt &C);
683681
Instruction *foldICmpDivConstant(ICmpInst &Cmp, BinaryOperator *Div,

0 commit comments

Comments
 (0)