[PATCH] D15165: change an assert when generating fmuladd to an ordinary 'if' check (PR25719)
Sanjay Patel via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 2 17:16:15 PST 2015
spatel updated this revision to Diff 41699.
spatel added a comment.
Patch updated with suggestions from http://reviews.llvm.org/D14891:
1. Changed 'else if' to plain 'if' for RHS check.
2. Used 'auto*' for dyn_casted vars.
3. Replaced 'getNUses() == 0' with 'use_empty()'.
http://reviews.llvm.org/D15165
Files:
lib/CodeGen/CGExprScalar.cpp
test/CodeGen/fp-contract-pragma.cpp
Index: test/CodeGen/fp-contract-pragma.cpp
===================================================================
--- test/CodeGen/fp-contract-pragma.cpp
+++ test/CodeGen/fp-contract-pragma.cpp
@@ -62,3 +62,15 @@
return a * b + c;
}
+// If the multiply has multiple uses, don't produce fmuladd.
+// This used to assert (PR25719):
+// https://llvm.org/bugs/show_bug.cgi?id=25719
+
+float fp_contract_7(float a, float b, float c) {
+// CHECK: _Z13fp_contract_7fff
+// CHECK: %mul = fmul float %b, 2.000000e+00
+// CHECK-NEXT: fsub float %mul, %c
+ #pragma STDC FP_CONTRACT ON
+ return (a = 2 * b) - c;
+}
+
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -2564,19 +2564,17 @@
return nullptr;
// We have a potentially fusable op. Look for a mul on one of the operands.
- if (llvm::BinaryOperator* LHSBinOp = dyn_cast<llvm::BinaryOperator>(op.LHS)) {
- if (LHSBinOp->getOpcode() == llvm::Instruction::FMul) {
- assert(LHSBinOp->getNumUses() == 0 &&
- "Operations with multiple uses shouldn't be contracted.");
+ // Also, make sure that the mul result isn't used directly. In that case,
+ // there's no point creating a muladd operation.
+ if (auto *LHSBinOp = dyn_cast<llvm::BinaryOperator>(op.LHS)) {
+ if (LHSBinOp->getOpcode() == llvm::Instruction::FMul &&
+ LHSBinOp->use_empty())
return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, false, isSub);
- }
- } else if (llvm::BinaryOperator* RHSBinOp =
- dyn_cast<llvm::BinaryOperator>(op.RHS)) {
- if (RHSBinOp->getOpcode() == llvm::Instruction::FMul) {
- assert(RHSBinOp->getNumUses() == 0 &&
- "Operations with multiple uses shouldn't be contracted.");
+ }
+ if (auto *RHSBinOp = dyn_cast<llvm::BinaryOperator>(op.RHS)) {
+ if (RHSBinOp->getOpcode() == llvm::Instruction::FMul &&
+ RHSBinOp->use_empty())
return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub, false);
- }
}
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15165.41699.patch
Type: text/x-patch
Size: 2092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151203/3a754b44/attachment.bin>
More information about the cfe-commits
mailing list