diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-11-05 16:50:44 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-11-05 16:50:44 +0000 |
commit | 87aa10062c0170a6a8cb79427655a086cf253b97 (patch) | |
tree | dbfd48948ba83c1ead2f5c7164a36b1d5f36a582 /llvm/lib/Transforms | |
parent | 8b2a1f7fd92a858d8d71a4bc9dcbd20f8af62dc4 (diff) | |
download | bcm5719-llvm-87aa10062c0170a6a8cb79427655a086cf253b97.tar.gz bcm5719-llvm-87aa10062c0170a6a8cb79427655a086cf253b97.zip |
[InstCombine] loosen FP 0.0 constraint for fcmp+select substitution
It looks like we correctly removed edge cases with 0.0 from D50714,
but we were a bit conservative because getBinOpIdentity() doesn't
distinguish between +0.0 and -0.0 and 'nsz' is effectively always
true for fcmp (see discussion in:
https://bugs.llvm.org/show_bug.cgi?id=38086
Without this change, we would get regressions by canonicalizing
to +0.0 in all fcmp, and that's a step towards solving:
https://bugs.llvm.org/show_bug.cgi?id=39475
llvm-svn: 346143
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 00dcacccb40..724662f0128 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -75,13 +75,22 @@ static Instruction *foldSelectBinOpIdentity(SelectInst &Sel, else return nullptr; - // A select operand must be a binop, and the compare constant must be the - // identity constant for that binop. + // A select operand must be a binop. BinaryOperator *BO; - if (!match(Sel.getOperand(IsEq ? 1 : 2), m_BinOp(BO)) || - ConstantExpr::getBinOpIdentity(BO->getOpcode(), BO->getType(), true) != C) + if (!match(Sel.getOperand(IsEq ? 1 : 2), m_BinOp(BO))) return nullptr; + // The compare constant must be the identity constant for that binop. + // If this a floating-point compare with 0.0, any zero constant will do. + Type *Ty = BO->getType(); + Constant *IdC = ConstantExpr::getBinOpIdentity(BO->getOpcode(), Ty, true); + if (IdC != C) { + if (!IdC || !CmpInst::isFPPredicate(Pred)) + return nullptr; + if (!match(IdC, m_AnyZeroFP()) || !match(C, m_AnyZeroFP())) + return nullptr; + } + // Last, match the compare variable operand with a binop operand. Value *Y; if (!BO->isCommutative() && !match(BO, m_BinOp(m_Value(Y), m_Specific(X)))) |