llvm.org GIT mirror llvm / d70be0b
Make InstCombiner::FoldAndOfICmps create a ConstantRange that's the intersection of the LHS and RHS ConstantRanges and return "false" when the range is empty. This simplifies some code and catches some extra cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126744 91177308-0d34-0410-b5e6-96231b3b80d8 Anders Carlsson 8 years ago
2 changed file(s) with 21 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1313 #include "InstCombine.h"
1414 #include "llvm/Intrinsics.h"
1515 #include "llvm/Analysis/InstructionSimplify.h"
16 #include "llvm/Support/ConstantRange.h"
1617 #include "llvm/Support/PatternMatch.h"
1718 using namespace llvm;
1819 using namespace PatternMatch;
766767 LHSCC == ICmpInst::ICMP_SGE || LHSCC == ICmpInst::ICMP_SLE ||
767768 RHSCC == ICmpInst::ICMP_SGE || RHSCC == ICmpInst::ICMP_SLE)
768769 return 0;
769
770
771 // Make a constant range that's the intersection of the two icmp ranges.
772 // If the intersection is empty, we know that the result is false.
773 ConstantRange LHSRange =
774 ConstantRange::makeICmpRegion(LHSCC, LHSCst->getValue());
775 ConstantRange RHSRange =
776 ConstantRange::makeICmpRegion(RHSCC, RHSCst->getValue());
777
778 if (LHSRange.intersectWith(RHSRange).isEmptySet())
779 return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0);
780
770781 // We can't fold (ugt x, C) & (sgt x, C2).
771782 if (!PredicatesFoldable(LHSCC, RHSCC))
772783 return 0;
799810 case ICmpInst::ICMP_EQ:
800811 switch (RHSCC) {
801812 default: llvm_unreachable("Unknown integer condition code!");
802 case ICmpInst::ICMP_EQ: // (X == 13 & X == 15) -> false
803 case ICmpInst::ICMP_UGT: // (X == 13 & X > 15) -> false
804 case ICmpInst::ICMP_SGT: // (X == 13 & X > 15) -> false
805 return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0);
806813 case ICmpInst::ICMP_NE: // (X == 13 & X != 15) -> X == 13
807814 case ICmpInst::ICMP_ULT: // (X == 13 & X < 15) -> X == 13
808815 case ICmpInst::ICMP_SLT: // (X == 13 & X < 15) -> X == 13
850857 case ICmpInst::ICMP_SLT:
851858 switch (RHSCC) {
852859 default: llvm_unreachable("Unknown integer condition code!");
853 case ICmpInst::ICMP_EQ: // (X s< 13 & X == 15) -> false
854 case ICmpInst::ICMP_SGT: // (X s< 13 & X s> 15) -> false
855 return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0);
856860 case ICmpInst::ICMP_UGT: // (X s< 13 & X u> 15) -> no change
857861 break;
858862 case ICmpInst::ICMP_NE: // (X s< 13 & X != 15) -> X < 13
2525 ; CHECK-NEXT: and i32 %X, %Y
2626 ; CHECK-NEXT: ret
2727 }
28
29 define i1 @test4(i32 %X) {
30 %a = icmp ult i32 %X, 31
31 %b = icmp slt i32 %X, 0
32 %c = and i1 %a, %b
33 ret i1 %c
34 ; CHECK: @test4
35 ; CHECK-NEXT: ret i1 false
36 }