[PATCH] D50497: [AliasSetTracker] Do not treat experimental_guard intrinsic as memory writing instruction

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 9 01:59:37 PDT 2018


mkazantsev created this revision.
mkazantsev added reviewers: kuhar, george.burgess.iv, sanjoy, reames.

The `experimental_guard` intrinsic has memory write semantics to model the thread-exiting
logic, but does not do any actual writes to memory. Currently, `AliasSetTracker` treats it as a
normal memory write. As result, a loop-invariant load cannot be hoisted out of loop because
the guard may possibly alias with it.

This patch adds `experimental_guard` to list of exception intrinsics for `AliasSetTracker` so that
we can safely assume that it does not alias with any loads in loop.


https://reviews.llvm.org/D50497

Files:
  lib/Analysis/AliasSetTracker.cpp
  test/Transforms/LICM/hoist-mustexec.ll


Index: test/Transforms/LICM/hoist-mustexec.ll
===================================================================
--- test/Transforms/LICM/hoist-mustexec.ll
+++ test/Transforms/LICM/hoist-mustexec.ll
@@ -4,6 +4,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 declare void @f() nounwind
+declare void @llvm.experimental.guard(i1,...)
 
 ; constant fold on first ieration
 define i32 @test1(i32* noalias nocapture readonly %a) nounwind uwtable {
@@ -281,6 +282,31 @@
   ret i32 -1
 }
 
+define void @test-hoisting-in-presence-of-guards(i1 %c, i32* %p) {
+
+; CHECK-LABEL: @test-hoisting-in-presence-of-guards
+; CHECK:       entry:
+; CHECK:         %a = load i32, i32* %p
+; CHECK:         %invariant_cond = icmp ne i32 %a, 100
+; CHECK:       loop:
+
+entry:
+  br label %loop
+
+loop:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+  %iv.next = add i32 %iv, 1
+  %a = load i32, i32* %p
+  %invariant_cond = icmp ne i32 %a, 100
+  call void (i1, ...) @llvm.experimental.guard(i1 %invariant_cond) [ "deopt"() ]
+  %loop_cond = icmp slt i32 %iv.next, 1000
+  br i1 %loop_cond, label %loop, label %exit
+
+exit:
+  ret void
+}
+
+
 declare void @may_throw() inaccessiblememonly
 
 ; Test that we can sink a mustexecute load from loop header even in presence of
Index: lib/Analysis/AliasSetTracker.cpp
===================================================================
--- lib/Analysis/AliasSetTracker.cpp
+++ lib/Analysis/AliasSetTracker.cpp
@@ -443,6 +443,7 @@
       // FIXME: Add lifetime/invariant intrinsics (See: PR30807).
     case Intrinsic::assume:
     case Intrinsic::sideeffect:
+    case Intrinsic::experimental_guard:
       return;
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50497.159877.patch
Type: text/x-patch
Size: 1667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180809/627a2aaf/attachment.bin>


More information about the llvm-commits mailing list