mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-12 13:30:51 +00:00
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
This commit is contained in:
parent
32e20a45e5
commit
d70be0b2c1
@ -14,6 +14,7 @@
|
||||
#include "InstCombine.h"
|
||||
#include "llvm/Intrinsics.h"
|
||||
#include "llvm/Analysis/InstructionSimplify.h"
|
||||
#include "llvm/Support/ConstantRange.h"
|
||||
#include "llvm/Support/PatternMatch.h"
|
||||
using namespace llvm;
|
||||
using namespace PatternMatch;
|
||||
@ -767,7 +768,17 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
|
||||
LHSCC == ICmpInst::ICMP_SGE || LHSCC == ICmpInst::ICMP_SLE ||
|
||||
RHSCC == ICmpInst::ICMP_SGE || RHSCC == ICmpInst::ICMP_SLE)
|
||||
return 0;
|
||||
|
||||
|
||||
// Make a constant range that's the intersection of the two icmp ranges.
|
||||
// If the intersection is empty, we know that the result is false.
|
||||
ConstantRange LHSRange =
|
||||
ConstantRange::makeICmpRegion(LHSCC, LHSCst->getValue());
|
||||
ConstantRange RHSRange =
|
||||
ConstantRange::makeICmpRegion(RHSCC, RHSCst->getValue());
|
||||
|
||||
if (LHSRange.intersectWith(RHSRange).isEmptySet())
|
||||
return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0);
|
||||
|
||||
// We can't fold (ugt x, C) & (sgt x, C2).
|
||||
if (!PredicatesFoldable(LHSCC, RHSCC))
|
||||
return 0;
|
||||
@ -800,10 +811,6 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
|
||||
case ICmpInst::ICMP_EQ:
|
||||
switch (RHSCC) {
|
||||
default: llvm_unreachable("Unknown integer condition code!");
|
||||
case ICmpInst::ICMP_EQ: // (X == 13 & X == 15) -> false
|
||||
case ICmpInst::ICMP_UGT: // (X == 13 & X > 15) -> false
|
||||
case ICmpInst::ICMP_SGT: // (X == 13 & X > 15) -> false
|
||||
return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0);
|
||||
case ICmpInst::ICMP_NE: // (X == 13 & X != 15) -> X == 13
|
||||
case ICmpInst::ICMP_ULT: // (X == 13 & X < 15) -> X == 13
|
||||
case ICmpInst::ICMP_SLT: // (X == 13 & X < 15) -> X == 13
|
||||
@ -851,9 +858,6 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
|
||||
case ICmpInst::ICMP_SLT:
|
||||
switch (RHSCC) {
|
||||
default: llvm_unreachable("Unknown integer condition code!");
|
||||
case ICmpInst::ICMP_EQ: // (X s< 13 & X == 15) -> false
|
||||
case ICmpInst::ICMP_SGT: // (X s< 13 & X s> 15) -> false
|
||||
return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0);
|
||||
case ICmpInst::ICMP_UGT: // (X s< 13 & X u> 15) -> no change
|
||||
break;
|
||||
case ICmpInst::ICMP_NE: // (X s< 13 & X != 15) -> X < 13
|
||||
|
@ -26,3 +26,12 @@ define i32 @test3(i32 %X, i32 %Y) {
|
||||
; CHECK-NEXT: and i32 %X, %Y
|
||||
; CHECK-NEXT: ret
|
||||
}
|
||||
|
||||
define i1 @test4(i32 %X) {
|
||||
%a = icmp ult i32 %X, 31
|
||||
%b = icmp slt i32 %X, 0
|
||||
%c = and i1 %a, %b
|
||||
ret i1 %c
|
||||
; CHECK: @test4
|
||||
; CHECK-NEXT: ret i1 false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user