forked from OSchip/llvm-project
[InstCombine] Fold Select with binary op - FP opcodes
Summary: Follow up for https://reviews.llvm.org/rL339520 and https://reviews.llvm.org/rL338300 Alive: ``` %A = fcmp oeq float %x, 0.0 %B = fadd nsz float %x, %z %C = select i1 %A, float %B, float %y => %C = select i1 %A, float %z, float %y ---------- %A = fcmp oeq float %x, 0.0 %B = fadd nsz float %x, %z %C = select %A, float %B, float %y => %C = select %A, float %z, float %y Done: 1 Optimization is correct %A = fcmp une float %x, -0.0 %B = fadd nsz float %x, %z %C = select i1 %A, float %y, float %B => %C = select i1 %A, float %y, float %z ---------- %A = fcmp une float %x, -0.0 %B = fadd nsz float %x, %z %C = select %A, float %y, float %B => %C = select %A, float %y, float %z Done: 1 Optimization is correct ``` Reviewers: spatel, lebedev.ri Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D50714 llvm-svn: 340538
This commit is contained in:
parent
3ecabd709f
commit
43b0e25847
|
@ -56,19 +56,26 @@ static Value *createMinMax(InstCombiner::BuilderTy &Builder,
|
|||
|
||||
/// Replace a select operand based on an equality comparison with the identity
|
||||
/// constant of a binop.
|
||||
static Instruction *foldSelectBinOpIdentity(SelectInst &Sel) {
|
||||
static Instruction *foldSelectBinOpIdentity(SelectInst &Sel, const TargetLibraryInfo &TLI) {
|
||||
// The select condition must be an equality compare with a constant operand.
|
||||
// TODO: Support FP compares.
|
||||
Value *X;
|
||||
Constant *C;
|
||||
CmpInst::Predicate Pred;
|
||||
if (!match(Sel.getCondition(), m_ICmp(Pred, m_Value(X), m_Constant(C))) ||
|
||||
!ICmpInst::isEquality(Pred))
|
||||
if (!match(Sel.getCondition(), m_Cmp(Pred, m_Value(X), m_Constant(C))))
|
||||
return nullptr;
|
||||
|
||||
bool IsEq;
|
||||
if (ICmpInst::isEquality(Pred))
|
||||
IsEq = Pred == ICmpInst::ICMP_EQ;
|
||||
else if (Pred == FCmpInst::FCMP_OEQ)
|
||||
IsEq = true;
|
||||
else if (Pred == FCmpInst::FCMP_UNE)
|
||||
IsEq = false;
|
||||
else
|
||||
return nullptr;
|
||||
|
||||
// A select operand must be a binop, and the compare constant must be the
|
||||
// identity constant for that binop.
|
||||
bool IsEq = Pred == ICmpInst::ICMP_EQ;
|
||||
BinaryOperator *BO;
|
||||
if (!match(Sel.getOperand(IsEq ? 1 : 2), m_BinOp(BO)) ||
|
||||
ConstantExpr::getBinOpIdentity(BO->getOpcode(), BO->getType(), true) != C)
|
||||
|
@ -81,6 +88,12 @@ static Instruction *foldSelectBinOpIdentity(SelectInst &Sel) {
|
|||
if (!match(BO, m_c_BinOp(m_Value(Y), m_Specific(X))))
|
||||
return nullptr;
|
||||
|
||||
// +0.0 compares equal to -0.0, and so it does not behave as required for this
|
||||
// transform. Bail out if we can not exclude that possibility.
|
||||
if (isa<FPMathOperator>(BO))
|
||||
if (!BO->hasNoSignedZeros() && !CannotBeNegativeZero(Y, &TLI))
|
||||
return nullptr;
|
||||
|
||||
// BO = binop Y, X
|
||||
// S = { select (cmp eq X, C), BO, ? } or { select (cmp ne X, C), ?, BO }
|
||||
// =>
|
||||
|
@ -2000,7 +2013,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
|||
if (Instruction *Select = foldSelectCmpXchg(SI))
|
||||
return Select;
|
||||
|
||||
if (Instruction *Select = foldSelectBinOpIdentity(SI))
|
||||
if (Instruction *Select = foldSelectBinOpIdentity(SI, TLI))
|
||||
return Select;
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -143,38 +143,37 @@ define i32 @select_xor_inv_icmp2(i32 %x, i32 %y, i32 %z) {
|
|||
define float @select_fadd_fcmp(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Z:%.*]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, -0.0
|
||||
%B = fadd float %x, %z
|
||||
%B = fadd nsz float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fadd_fcmp_2(float %x, float %y, float %z) {
|
||||
define float @select_fadd_fcmp_2(float %x, float %y, float %v) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_2(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp ueq float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[Z:%.*]] = fadd float [[V:%.*]], 0.000000e+00
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[Z]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp ueq float %x, -0.0
|
||||
%B = fadd float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
%A = fcmp une float %x, -0.0
|
||||
%z = fadd float %v, 0.0 ; cannot produce -0.0
|
||||
%B = fadd float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fadd_fcmp_3(float %x, float %y, float %z) {
|
||||
define float @select_fadd_fcmp_3(float %x, float %y) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_3(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp one float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float 6.000000e+00
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp one float %x, -0.0
|
||||
%B = fadd float %z, %x
|
||||
%A = fcmp une float %x, -0.0
|
||||
%B = fadd float 6.0, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
@ -182,25 +181,49 @@ define float @select_fadd_fcmp_3(float %x, float %y, float %z) {
|
|||
define float @select_fadd_fcmp_4(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_4(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[Z:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp une float %x, -0.0
|
||||
%B = fadd float %z, %x
|
||||
%B = fadd nsz float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fadd_fcmp_5(float %x, float %y, float %v) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_5(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[Z:%.*]] = fadd float [[V:%.*]], 0.000000e+00
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Z]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, -0.0
|
||||
%z = fadd float %v, 0.0 ; cannot produce -0.0
|
||||
%B = fadd float %z, %x
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fadd_fcmp_6(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_6(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float 6.000000e+00, float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, -0.0
|
||||
%B = fadd float %x, 6.0
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fmul_fcmp(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fmul_fcmp(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fmul float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Z:%.*]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 1.0
|
||||
%B = fmul float %x, %z
|
||||
%B = fmul nsz float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
@ -208,12 +231,11 @@ define float @select_fmul_fcmp(float %x, float %y, float %z) {
|
|||
define float @select_fsub_fcmp(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fsub_fcmp(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fsub float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Z:%.*]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 0.0
|
||||
%B = fsub float %z, %x
|
||||
%B = fsub nsz float %z, %x
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
@ -221,12 +243,11 @@ define float @select_fsub_fcmp(float %x, float %y, float %z) {
|
|||
define float @select_fdiv_fcmp(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fdiv_fcmp(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fdiv float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Z:%.*]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 1.0
|
||||
%B = fdiv float %z, %x
|
||||
%B = fdiv nsz float %z, %x
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
@ -507,19 +528,21 @@ define i32 @select_or_icmp_bad(i32 %x, i32 %y, i32 %z) {
|
|||
ret i32 %C
|
||||
}
|
||||
|
||||
; Invalid identity constant for FP op
|
||||
define float @select_fadd_fcmp_bad(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, -1.0
|
||||
%B = fadd float %x, %z
|
||||
%B = fadd nsz float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid comparison type
|
||||
define float @select_fadd_fcmp_bad_2(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_2(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp ueq float [[X:%.*]], -1.000000e+00
|
||||
|
@ -533,6 +556,7 @@ define float @select_fadd_fcmp_bad_2(float %x, float %y, float %z) {
|
|||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid comparison type
|
||||
define float @select_fadd_fcmp_bad_3(float %x, float %y, float %z, float %k) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_3(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp one float [[X:%.*]], [[K:%.*]]
|
||||
|
@ -546,6 +570,7 @@ define float @select_fadd_fcmp_bad_3(float %x, float %y, float %z, float %k) {
|
|||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid order of operands of select
|
||||
define float @select_fadd_fcmp_bad_4(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_4(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], -0.000000e+00
|
||||
|
@ -559,14 +584,200 @@ define float @select_fadd_fcmp_bad_4(float %x, float %y, float %z) {
|
|||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid comparison type
|
||||
define float @select_fadd_fcmp_bad_5(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_5(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp one float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp one float %x, -0.0
|
||||
%B = fadd nsz float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid order of operands of select
|
||||
define float @select_fadd_fcmp_bad_6(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_6(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, -0.0
|
||||
%B = fadd nsz float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Do not transform if we have signed zeros and if Z is possibly negative zero
|
||||
define float @select_fadd_fcmp_bad_7(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_7(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, -0.0
|
||||
%B = fadd float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid comparison type
|
||||
define float @select_fadd_fcmp_bad_8(float %x, float %y, float %v) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_8(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp one float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[Z:%.*]] = fadd float [[V:%.*]], -1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[Z]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp one float %x, -0.0
|
||||
%z = fadd float %v, -1.0
|
||||
%B = fadd float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid comparison type
|
||||
define float @select_fadd_fcmp_bad_9(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_9(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp one float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp one float %x, -0.0
|
||||
%B = fadd nsz float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid comparison type
|
||||
define float @select_fadd_fcmp_bad_10(float %x, float %y, float %v) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_10(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp one float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[Z:%.*]] = fadd float [[V:%.*]], 0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[Z]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp one float %x, -0.0
|
||||
%z = fadd float %v, 0.0 ; cannot produce -0.0
|
||||
%B = fadd float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Do not transform if Z is possibly negative zero
|
||||
define float @select_fadd_fcmp_bad_11(float %x, float %y, float %v) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_11(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[Z:%.*]] = fadd float [[V:%.*]], -1.000000e+00
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[Z]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp une float %x, -0.0
|
||||
%z = fadd float %v, -1.0
|
||||
%B = fadd nsz float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Do not transform if we have signed zeros and if Z is possibly negative zero
|
||||
define float @select_fadd_fcmp_bad_12(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_12(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp une float %x, -0.0
|
||||
%B = fadd float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid order of operands of select
|
||||
define float @select_fadd_fcmp_bad_13(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_13(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, -0.0
|
||||
%B = fadd nsz float %x, %z
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid identity constant for FP op
|
||||
define float @select_fadd_fcmp_bad_14(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_14(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], -1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp une float %x, -1.0
|
||||
%B = fadd nsz float %x, %z
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid identity constant for FP op
|
||||
define float @select_fadd_fcmp_bad_15(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_15(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp une float [[X:%.*]], 0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[Y:%.*]], float [[B]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp une float %x, 0.0
|
||||
%B = fadd nsz float %z, %x
|
||||
%C = select i1 %A, float %y, float %B
|
||||
ret float %C
|
||||
}
|
||||
|
||||
; Invalid identity constant for FP op
|
||||
define float @select_fadd_fcmp_bad_16(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fadd_fcmp_bad_16(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fadd nsz float [[Z:%.*]], [[X]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 0.0
|
||||
%B = fadd nsz float %z, %x
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fmul_fcmp_bad(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fmul_fcmp_bad(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 3.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fmul float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[B:%.*]] = fmul nsz float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 3.0
|
||||
%B = fmul nsz float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fmul_fcmp_bad_2(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fmul_fcmp_bad_2(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fmul float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 1.0
|
||||
%B = fmul float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
|
@ -585,32 +796,71 @@ define float @select_fmul_icmp_bad(float %x, float %y, float %z, i32 %k) {
|
|||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fmul_icmp_bad_2(float %x, float %y, float %z, i32 %k) {
|
||||
; CHECK-LABEL: @select_fmul_icmp_bad_2(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[K:%.*]], 0
|
||||
; CHECK-NEXT: [[B:%.*]] = fmul nsz float [[X:%.*]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = icmp eq i32 %k, 0
|
||||
%B = fmul nsz float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fdiv_fcmp_bad(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fdiv_fcmp_bad(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 3.000000e+00
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fdiv float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 3.0
|
||||
%A = fcmp oeq float %x, 1.0
|
||||
%B = fdiv float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fdiv_fcmp_bad_2(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fdiv_fcmp_bad_2(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 3.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fdiv nsz float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 3.0
|
||||
%B = fdiv nsz float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fsub_fcmp_bad(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fsub_fcmp_bad(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 0.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fsub float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 1.0
|
||||
%A = fcmp oeq float %x, 0.0
|
||||
%B = fsub float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define float @select_fsub_fcmp_bad_2(float %x, float %y, float %z) {
|
||||
; CHECK-LABEL: @select_fsub_fcmp_bad_2(
|
||||
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
|
||||
; CHECK-NEXT: [[B:%.*]] = fsub nsz float [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
|
||||
; CHECK-NEXT: ret float [[C]]
|
||||
;
|
||||
%A = fcmp oeq float %x, 1.0
|
||||
%B = fsub nsz float %x, %z
|
||||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
define i32 @select_sub_icmp_bad(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-LABEL: @select_sub_icmp_bad(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
|
||||
|
|
Loading…
Reference in New Issue