llvm.org GIT mirror llvm / f0a3e25
[InstSimplify] restrict icmp fold with 2 sdiv exact operands (PR32949) These folds were introduced with https://reviews.llvm.org/rL127064 as part of solving: https://bugs.llvm.org/show_bug.cgi?id=9343 As shown here: http://rise4fun.com/Alive/C8 ...however, the sdiv exact case needs a stronger predicate. I opted for duplicated code instead of adding another fallthrough because I think that's easier to read (and edit in case we need/want to restrict/loosen the predicates any more). This should fix: https://bugs.llvm.org/show_bug.cgi?id=32949 https://bugs.llvm.org/show_bug.cgi?id=32948 Differential Revision: https://reviews.llvm.org/D32954 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303104 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
2 changed file(s) with 16 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
28262826 break;
28272827 case Instruction::UDiv:
28282828 case Instruction::LShr:
2829 if (ICmpInst::isSigned(Pred))
2829 if (ICmpInst::isSigned(Pred) || !LBO->isExact() || !RBO->isExact())
28302830 break;
2831 LLVM_FALLTHROUGH;
2831 if (Value *V = SimplifyICmpInst(Pred, LBO->getOperand(0),
2832 RBO->getOperand(0), Q, MaxRecurse - 1))
2833 return V;
2834 break;
28322835 case Instruction::SDiv:
2836 if (!ICmpInst::isEquality(Pred) || !LBO->isExact() || !RBO->isExact())
2837 break;
2838 if (Value *V = SimplifyICmpInst(Pred, LBO->getOperand(0),
2839 RBO->getOperand(0), Q, MaxRecurse - 1))
2840 return V;
2841 break;
28332842 case Instruction::AShr:
28342843 if (!LBO->isExact() || !RBO->isExact())
28352844 break;
597597 ret i1 %C
598598 }
599599
600 ; FIXME: But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949
600 ; But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949
601601
602602 define i1 @sdiv_exact_not_equality(i32 %Z) {
603603 ; CHECK-LABEL: @sdiv_exact_not_equality(
604 ; CHECK-NEXT: ret i1 true
604 ; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 10, %Z
605 ; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 20, %Z
606 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]]
607 ; CHECK-NEXT: ret i1 [[C]]
605608 ;
606609 %A = sdiv exact i32 10, %Z
607610 %B = sdiv exact i32 20, %Z