[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
Mon Oct 26 06:56:35 PDT 2015
sdmitrouk created this revision.
sdmitrouk added reviewers: hfinkel, joker.eph.
sdmitrouk added subscribers: llvm-commits, scanon, resistor.
sdmitrouk set the repository for this revision to rL LLVM.
isSafeToSpeculativelyExecute() is not enough, because it's result
it taken into account only when it's positive and we need to forbid
the case where result is negative.
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 kexc kround 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
@@ -690,6 +690,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->hasKeepExceptions() || MathOp->hasKeepRounding())
+ return false;
+
return isGuaranteedToExecute(Inst, DT, CurLoop, SafetyInfo);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14078.38414.patch
Type: text/x-patch
Size: 1625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151026/79c9be62/attachment-0001.bin>
More information about the llvm-commits
mailing list