mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[InstSimplify] Fold min/max based on dominating condition
If we have a dominating condition that x >= y, then umax(x, y) is x, etc. I'm doing this in InstSimplify as the corresponding transform for the select form is also done there. Differential Revision: https://reviews.llvm.org/D87168
This commit is contained in:
parent
ecd979f4bb
commit
1eb2ecc5c6
@ -5326,6 +5326,13 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
|
||||
if (isICmpTrue(Pred, Op1, Op0, Q.getWithoutUndef(), RecursionLimit))
|
||||
return Op1;
|
||||
|
||||
if (Optional<bool> Imp =
|
||||
isImpliedByDomCondition(Pred, Op0, Op1, Q.CxtI, Q.DL))
|
||||
return *Imp ? Op0 : Op1;
|
||||
if (Optional<bool> Imp =
|
||||
isImpliedByDomCondition(Pred, Op1, Op0, Q.CxtI, Q.DL))
|
||||
return *Imp ? Op1 : Op0;
|
||||
|
||||
break;
|
||||
}
|
||||
case Intrinsic::usub_with_overflow:
|
||||
|
@ -2139,11 +2139,9 @@ define i8 @umax_dom_cond_uge(i8 %x, i8 %y) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
|
||||
; CHECK: true:
|
||||
; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
; CHECK-NEXT: ret i8 [[X]]
|
||||
; CHECK: false:
|
||||
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
; CHECK-NEXT: ret i8 [[Y]]
|
||||
;
|
||||
%cmp = icmp uge i8 %x, %y
|
||||
br i1 %cmp, label %true, label %false
|
||||
@ -2162,11 +2160,9 @@ define i8 @umax_dom_cond_ugt(i8 %x, i8 %y) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
|
||||
; CHECK: true:
|
||||
; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
; CHECK-NEXT: ret i8 [[X]]
|
||||
; CHECK: false:
|
||||
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
; CHECK-NEXT: ret i8 [[Y]]
|
||||
;
|
||||
%cmp = icmp ugt i8 %x, %y
|
||||
br i1 %cmp, label %true, label %false
|
||||
@ -2185,11 +2181,9 @@ define i8 @umax_dom_cond_ule(i8 %x, i8 %y) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
|
||||
; CHECK: true:
|
||||
; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
; CHECK-NEXT: ret i8 [[Y]]
|
||||
; CHECK: false:
|
||||
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
; CHECK-NEXT: ret i8 [[X]]
|
||||
;
|
||||
%cmp = icmp ule i8 %x, %y
|
||||
br i1 %cmp, label %true, label %false
|
||||
@ -2208,11 +2202,9 @@ define i8 @umax_dom_cond_ult(i8 %x, i8 %y) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
|
||||
; CHECK: true:
|
||||
; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
; CHECK-NEXT: ret i8 [[Y]]
|
||||
; CHECK: false:
|
||||
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
; CHECK-NEXT: ret i8 [[X]]
|
||||
;
|
||||
%cmp = icmp ult i8 %x, %y
|
||||
br i1 %cmp, label %true, label %false
|
||||
@ -2231,11 +2223,9 @@ define i8 @umin_dom_cond_uge(i8 %x, i8 %y) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
|
||||
; CHECK: true:
|
||||
; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
; CHECK-NEXT: ret i8 [[Y]]
|
||||
; CHECK: false:
|
||||
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
; CHECK-NEXT: ret i8 [[X]]
|
||||
;
|
||||
%cmp = icmp uge i8 %x, %y
|
||||
br i1 %cmp, label %true, label %false
|
||||
@ -2254,11 +2244,9 @@ define i8 @smax_dom_cond_sge(i8 %x, i8 %y) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
|
||||
; CHECK: true:
|
||||
; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
; CHECK-NEXT: ret i8 [[X]]
|
||||
; CHECK: false:
|
||||
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
; CHECK-NEXT: ret i8 [[Y]]
|
||||
;
|
||||
%cmp = icmp sge i8 %x, %y
|
||||
br i1 %cmp, label %true, label %false
|
||||
@ -2277,11 +2265,9 @@ define i8 @smin_dom_cond_sge(i8 %x, i8 %y) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
|
||||
; CHECK: true:
|
||||
; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
; CHECK-NEXT: ret i8 [[Y]]
|
||||
; CHECK: false:
|
||||
; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 [[Y]])
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
; CHECK-NEXT: ret i8 [[X]]
|
||||
;
|
||||
%cmp = icmp sge i8 %x, %y
|
||||
br i1 %cmp, label %true, label %false
|
||||
|
Loading…
Reference in New Issue
Block a user