llvm.org GIT mirror llvm / 6d2022f
[InstCombine] restrict icmp fold with 2 sdiv exact operands (PR32949) This is the InstCombine counterpart to D32954. I added some comments about the code duplication in: rL302436 Alive-based verification: http://rise4fun.com/Alive/dPw This is a 2nd fix for the problem reported in: https://bugs.llvm.org/show_bug.cgi?id=32949 Differential Revision: https://reviews.llvm.org/D32970 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303105 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
2 changed file(s) with 13 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
30673067 }
30683068 }
30693069 break;
3070
30703071 case Instruction::UDiv:
30713072 case Instruction::LShr:
3072 if (I.isSigned())
3073 if (I.isSigned() || !BO0->isExact() || !BO1->isExact())
30733074 break;
3074 LLVM_FALLTHROUGH;
3075 return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0));
3076
30753077 case Instruction::SDiv:
3078 if (!I.isEquality() || !BO0->isExact() || !BO1->isExact())
3079 break;
3080 return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0));
3081
30763082 case Instruction::AShr:
30773083 if (!BO0->isExact() || !BO1->isExact())
30783084 break;
30793085 return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0));
3086
30803087 case Instruction::Shl: {
30813088 bool NUW = BO0->hasNoUnsignedWrap() && BO1->hasNoUnsignedWrap();
30823089 bool NSW = BO0->hasNoSignedWrap() && BO1->hasNoSignedWrap();
694694 ret i1 %C
695695 }
696696
697 ; FIXME: The above transform only works for equality predicates.
697 ; The above transform only works for equality predicates.
698698
699699 define i1 @PR32949(i32 %X, i32 %Y, i32 %Z) {
700700 ; CHECK-LABEL: @PR32949(
701 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 %X, %Y
701 ; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 %X, %Z
702 ; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 %Y, %Z
703 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[A]], [[B]]
702704 ; CHECK-NEXT: ret i1 [[C]]
703705 ;
704706 %A = sdiv exact i32 %X, %Z