[PATCH] D50364: [LICM] Hoist assumes out of loops

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 7 10:57:49 PDT 2018


reames updated this revision to Diff 159549.
reames added a comment.

Rebased on top of newly submitted tests to address review comment


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.159549.patch
Type: text/x-patch
Size: 1187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180807/5344320c/attachment.bin>


More information about the llvm-commits mailing list