[PATCH] D14078: [FPEnv Core 13/14] Don't hoist FP-ops with side-effects in LICM
Sergey Dmitrouk via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 4 12:18:23 PST 2015
sdmitrouk updated this revision to Diff 41923.
sdmitrouk added a comment.
Rename flags.
Repository:
rL LLVM
http://reviews.llvm.org/D14078
Files:
lib/Transforms/Scalar/LICM.cpp
test/Transforms/LICM/fpenv.ll
Index: test/Transforms/LICM/fpenv.ll
===================================================================
--- /dev/null
+++ test/Transforms/LICM/fpenv.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -O3 -S | FileCheck %s
+
+define void @fdiv-is-not-hoisted-out-of-loop(i32 %n) {
+; CHECK-LABEL: @fdiv-is-not-hoisted-out-of-loop(
+; CHECK: for.body:
+; CHECK: fdiv
+entry:
+ %cmp2 = icmp sgt i32 %n, 0
+ br i1 %cmp2, label %for.body.lr.ph, label %for.end
+
+for.body.lr.ph:
+ %0 = add i32 %n, -1
+ br label %for.body
+
+for.body:
+ %i.03 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
+ %div = fdiv double 0.000000e+00, 0.000000e+00
+ tail call void @process(double %div)
+ %inc = add nuw nsw i32 %i.03, 1
+ %exitcond = icmp eq i32 %i.03, %0
+ br i1 %exitcond, label %for.end.loopexit, label %for.body
+
+for.end.loopexit:
+ br label %for.end
+
+for.end:
+ ret void
+}
+
+declare void @process(double) nounwind
Index: lib/Transforms/Scalar/LICM.cpp
===================================================================
--- lib/Transforms/Scalar/LICM.cpp
+++ lib/Transforms/Scalar/LICM.cpp
@@ -694,6 +694,13 @@
if (isSafeToSpeculativelyExecute(&Inst, CtxI, DT, TLI))
return true;
+ // isSafeToSpeculativelyExecute() is not enough, because its result is
+ // taken into account only when it's positive and we need to forbid the case
+ // where its result is negative.
+ if (const FPMathOperator *MathOp = dyn_cast<FPMathOperator>(&Inst))
+ if (!MathOp->hasNoExceptions() || !MathOp->hasNoRounding())
+ return false;
+
return isGuaranteedToExecute(Inst, DT, CurLoop, SafetyInfo);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14078.41923.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151204/af44d989/attachment.bin>
More information about the llvm-commits
mailing list