[PATCH] D14073: [FPEnv Core 08/14] Do not simplify expressions with FPEnv access
Sergey Dmitrouk via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 4 12:09:51 PST 2015
sdmitrouk updated this revision to Diff 41917.
sdmitrouk added a comment.
Update of test per flags rename and correction of one condition (need to ignore non-floating-point types).
Repository:
rL LLVM
http://reviews.llvm.org/D14073
Files:
include/llvm/IR/Constants.h
lib/Analysis/ConstantFolding.cpp
lib/IR/Constants.cpp
test/Transforms/EarlyCSE/fpenv.ll
Index: test/Transforms/EarlyCSE/fpenv.ll
===================================================================
--- /dev/null
+++ test/Transforms/EarlyCSE/fpenv.ll
@@ -0,0 +1,24 @@
+; %val.true and %val.false should not be moved inside phi-node as constant
+; expressions as such transformation looses fast-math flags.
+; RUN: opt < %s -S -early-cse | FileCheck %s
+
+define double @do-not-turn-into-constexpr(double %x) {
+; CHECK-LABEL: @do-not-turn-into-constexpr(
+; CHECK: %val.true = fmul
+; CHECK: %val.false = fmul
+entry:
+ %cmp = fcmp oeq double %x, 0.000000e+00
+ br i1 %cmp, label %cond.true, label %cond.false
+
+cond.true: ; preds = %entry
+ %val.true = fmul nrnd double 1.000000e+300, 1.000000e+300
+ br label %cond.end
+
+cond.false: ; preds = %entry
+ %val.false = fmul nrnd double 1.000000e-300, 1.000000e-300
+ br label %cond.end
+
+cond.end: ; preds = %cond.false, %cond.true
+ %cond = phi double [ %val.true, %cond.true ], [ %val.false, %cond.false ]
+ ret double %cond
+}
Index: lib/IR/Constants.cpp
===================================================================
--- lib/IR/Constants.cpp
+++ lib/IR/Constants.cpp
@@ -1880,7 +1880,8 @@
Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2,
unsigned Flags, Type *OnlyIfReducedTy,
- FastMathFlags FMF) {
+ FastMathFlags FMF,
+ bool Strict) {
// Check the operands for consistency first.
assert(Opcode >= Instruction::BinaryOpsBegin &&
Opcode < Instruction::BinaryOpsEnd &&
@@ -1952,6 +1953,13 @@
if (OnlyIfReducedTy == C1->getType())
return nullptr;
+ if (C1->getType()->isFPOrFPVectorTy()) {
+ // ConstantExpression can't store these flags, which can lead to going
+ // against them.
+ if (Strict && (!FMF.noExceptions() || !FMF.noRounding()))
+ return nullptr;
+ }
+
Constant *ArgVec[] = { C1, C2 };
ConstantExprKeyType Key(Opcode, ArgVec, 0, Flags);
Index: lib/Analysis/ConstantFolding.cpp
===================================================================
--- lib/Analysis/ConstantFolding.cpp
+++ lib/Analysis/ConstantFolding.cpp
@@ -1030,7 +1030,8 @@
return C;
}
- return ConstantExpr::get(Opcode, Ops[0], Ops[1], 0, nullptr, FMF);
+ return ConstantExpr::get(Opcode, Ops[0], Ops[1], 0, nullptr,
+ FMF, /* Strict = */ true);
}
switch (Opcode) {
Index: include/llvm/IR/Constants.h
===================================================================
--- include/llvm/IR/Constants.h
+++ include/llvm/IR/Constants.h
@@ -1101,7 +1101,8 @@
/// \param OnlyIfReducedTy see \a getWithOperands() docs.
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr,
- FastMathFlags FMF = FastMathFlags());
+ FastMathFlags FMF = FastMathFlags(),
+ bool Strict = false);
/// \brief Return an ICmp or FCmp comparison operator constant expression.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14073.41917.patch
Type: text/x-patch
Size: 3241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151204/c53acf58/attachment.bin>
More information about the llvm-commits
mailing list