mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-01 00:33:09 +00:00
Added inst-combine for 'MIN(MIN(A, 97), 23)' and 'MAX(MAX(A, 23), 97)'
This removes TODO added in r208849 [http://reviews.llvm.org/D3629] MIN(MIN(A, 97), 23) -> MIN(A, 23) MAX(MAX(A, 23), 97) -> MAX(A, 97) Differential Revision: http://reviews.llvm.org/D3785 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209110 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cb596baadd
commit
306cd28e21
@ -651,24 +651,32 @@ Instruction *InstCombiner::FoldSPFofSPF(Instruction *Inner,
|
||||
return ReplaceInstUsesWith(Outer, C);
|
||||
}
|
||||
|
||||
// MIN(MIN(A, 23), 97) -> MIN(A, 23)
|
||||
// MAX(MAX(A, 97), 23) -> MAX(A, 97)
|
||||
if (SPF1 == SPF2) {
|
||||
if (ConstantInt *CB = dyn_cast<ConstantInt>(B)) {
|
||||
if (ConstantInt *CC = dyn_cast<ConstantInt>(C)) {
|
||||
APInt ACB = CB->getValue();
|
||||
APInt ACC = CC->getValue();
|
||||
|
||||
// MIN(MIN(A, 23), 97) -> MIN(A, 23)
|
||||
// MAX(MAX(A, 97), 23) -> MAX(A, 97)
|
||||
if ((SPF1 == SPF_UMIN && ACB.ule(ACC)) ||
|
||||
(SPF1 == SPF_SMIN && ACB.sle(ACC)) ||
|
||||
(SPF1 == SPF_UMAX && ACB.uge(ACC)) ||
|
||||
(SPF1 == SPF_SMAX && ACB.sge(ACC)))
|
||||
return ReplaceInstUsesWith(Outer, Inner);
|
||||
|
||||
// MIN(MIN(A, 97), 23) -> MIN(A, 23)
|
||||
// MAX(MAX(A, 23), 97) -> MAX(A, 97)
|
||||
if ((SPF1 == SPF_UMIN && ACB.ugt(ACC)) ||
|
||||
(SPF1 == SPF_SMIN && ACB.sgt(ACC)) ||
|
||||
(SPF1 == SPF_UMAX && ACB.ult(ACC)) ||
|
||||
(SPF1 == SPF_SMAX && ACB.slt(ACC))) {
|
||||
Outer.replaceUsesOfWith(Inner, A);
|
||||
return &Outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: MIN(MIN(A, 97), 23) -> MIN(A, 23)
|
||||
// TODO: MAX(MAX(A, 23), 97) -> MAX(A, 97)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -1078,4 +1078,56 @@ entry:
|
||||
ret i32 %retval
|
||||
; CHECK-LABEL: @test71(
|
||||
; CHECK: ret i32 %cond
|
||||
}
|
||||
|
||||
; SMIN(SMIN(X, 92), 11) -> SMIN(X, 11)
|
||||
define i32 @test72(i32 %x) {
|
||||
%cmp = icmp sgt i32 %x, 92
|
||||
%cond = select i1 %cmp, i32 92, i32 %x
|
||||
%cmp3 = icmp sgt i32 %cond, 11
|
||||
%retval = select i1 %cmp3, i32 11, i32 %cond
|
||||
ret i32 %retval
|
||||
; CHECK-LABEL: @test72(
|
||||
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 11
|
||||
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 11, i32 %x
|
||||
; CHECK-NEXT: ret i32 [[SEL]]
|
||||
}
|
||||
|
||||
; MIN(MIN(X, 83), 24) -> MIN(X, 24)
|
||||
define i32 @test73(i32 %x) {
|
||||
%cmp = icmp ugt i32 %x, 83
|
||||
%cond = select i1 %cmp, i32 83, i32 %x
|
||||
%cmp3 = icmp ugt i32 %cond, 24
|
||||
%retval = select i1 %cmp3, i32 24, i32 %cond
|
||||
ret i32 %retval
|
||||
; CHECK-LABEL: @test73(
|
||||
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %x, 24
|
||||
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 24, i32 %x
|
||||
; CHECK-NEXT: ret i32 [[SEL]]
|
||||
}
|
||||
|
||||
; SMAX(SMAX(X, 36), 75) -> SMAX(X, 75)
|
||||
define i32 @test74(i32 %x) {
|
||||
%cmp = icmp slt i32 %x, 36
|
||||
%cond = select i1 %cmp, i32 36, i32 %x
|
||||
%cmp3 = icmp slt i32 %cond, 75
|
||||
%retval = select i1 %cmp3, i32 75, i32 %cond
|
||||
ret i32 %retval
|
||||
; CHECK-LABEL: @test74(
|
||||
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 75
|
||||
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 75, i32 %x
|
||||
; CHECK-NEXT: ret i32 [[SEL]]
|
||||
}
|
||||
|
||||
; MAX(MAX(X, 47), 68) -> MAX(X, 68)
|
||||
define i32 @test75(i32 %x) {
|
||||
%cmp = icmp ult i32 %x, 47
|
||||
%cond = select i1 %cmp, i32 47, i32 %x
|
||||
%cmp3 = icmp ult i32 %cond, 68
|
||||
%retval = select i1 %cmp3, i32 68, i32 %cond
|
||||
ret i32 %retval
|
||||
; CHECK-LABEL: @test75(
|
||||
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %x, 68
|
||||
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 68, i32 %x
|
||||
; CHECK-NEXT: ret i32 [[SEL]]
|
||||
}
|
Loading…
Reference in New Issue
Block a user