mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-15 23:31:37 +00:00
InstCombine: Turn (x != 0 & x <u C) into the canonical range check form (x-1 <u C-1)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219585 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c00cd8e3c8
commit
2b7b804fcc
@ -930,6 +930,8 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
|
||||
case ICmpInst::ICMP_ULT:
|
||||
if (LHSCst == SubOne(RHSCst)) // (X != 13 & X u< 14) -> X < 13
|
||||
return Builder->CreateICmpULT(Val, LHSCst);
|
||||
if (LHSCst->isNullValue()) // (X != 0 & X u< 14) -> X-1 u< 13
|
||||
return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false, true);
|
||||
break; // (X != 13 & X u< 15) -> no change
|
||||
case ICmpInst::ICMP_SLT:
|
||||
if (LHSCst == SubOne(RHSCst)) // (X != 13 & X s< 14) -> X < 13
|
||||
|
@ -66,3 +66,14 @@ define i1 @test7(i32 %i, i1 %b) {
|
||||
%and2 = and i1 %and1, %cmp2
|
||||
ret i1 %and2
|
||||
}
|
||||
|
||||
define i1 @test8(i32 %i) {
|
||||
; CHECK-LABEL: @test8(
|
||||
; CHECK-NEXT: [[DEC:%.*]] = add i32 %i, -1
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[DEC]], 13
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
%cmp1 = icmp ne i32 %i, 0
|
||||
%cmp2 = icmp ult i32 %i, 14
|
||||
%cond = and i1 %cmp1, %cmp2
|
||||
ret i1 %cond
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user