[PATCH] D50364: [LICM] Hoist assumes out of loops
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 6 15:14:43 PDT 2018
reames created this revision.
reames added reviewers: hfinkel, mkazantsev.
Herald added subscribers: llvm-commits, bollu, mcrosier.
If we have an assume which is known to execute and whose operand is invariant, we can lift that into the pre-header. So long as we don't change which paths the assume executes on, this is a legal transformation. It's likely to be a useful canonicalization as other transforms only look for dominating assumes.
Repository:
rL LLVM
https://reviews.llvm.org/D50364
Files:
lib/Transforms/Scalar/LICM.cpp
test/Transforms/LICM/assume.ll
Index: test/Transforms/LICM/assume.ll
===================================================================
--- test/Transforms/LICM/assume.ll
+++ test/Transforms/LICM/assume.ll
@@ -36,9 +36,9 @@
define void @f_1(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @f_1(
; CHECK-LABEL: entry:
+; CHECK: call void @llvm.assume(i1 %cond)
; CHECK: %val = load i32, i32* %ptr
; CHECK-LABEL: loop:
-; CHECK: call void @llvm.assume(i1 %cond)
entry:
br label %loop
Index: lib/Transforms/Scalar/LICM.cpp
===================================================================
--- lib/Transforms/Scalar/LICM.cpp
+++ lib/Transforms/Scalar/LICM.cpp
@@ -657,6 +657,15 @@
if (CI->mayThrow())
return false;
+ if (Function *F = CI->getCalledFunction())
+ switch (F->getIntrinsicID()) {
+ default: break;
+ // TODO: support invariant.start, and experimental.guard here
+ case Intrinsic::assume:
+ // Assumes don't actually alias anything or throw
+ return true;
+ };
+
// Handle simple cases by querying alias analysis.
FunctionModRefBehavior Behavior = AA->getModRefBehavior(CI);
if (Behavior == FMRB_DoesNotAccessMemory)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50364.159406.patch
Type: text/x-patch
Size: 1187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180806/54753adf/attachment.bin>
More information about the llvm-commits
mailing list