[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 22:47:50 PDT 2018


mkazantsev updated this revision to Diff 160058.
mkazantsev edited the summary of this revision.
mkazantsev added a comment.

I hope that this approach is a correct one. Also added a dedicated test.


https://reviews.llvm.org/D50497

Files:
  lib/Analysis/AliasSetTracker.cpp
  test/Analysis/AliasSet/intrinsics.ll
  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: test/Analysis/AliasSet/intrinsics.ll
===================================================================
--- test/Analysis/AliasSet/intrinsics.ll
+++ test/Analysis/AliasSet/intrinsics.ll
@@ -16,4 +16,22 @@
   ret void
 }
 
+; CHECK: Alias sets for function 'test2':
+; CHECK: Alias Set Tracker: 3 alias sets for 2 pointer values.
+; CHECK:   AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod       Pointers: (i8* %a, 1)
+; CHECK:   AliasSet[0x{{[0-9a-f]+}}, 1] may alias, Ref
+; CHECK:     1 Unknown instructions:   call void (i1, ...) @llvm.experimental.guard(i1 %cond1) [ "deopt"() ]
+; CHECK:   AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod       Pointers: (i8* %b, 1)
+define void @test2(i32 %c) {
+entry:
+  %a = alloca i8, align 1
+  %b = alloca i8, align 1
+  store i8 1, i8* %a, align 1
+  %cond1 = icmp ne i32 %c, 0
+  call void (i1, ...) @llvm.experimental.guard(i1 %cond1)["deopt"()]
+  store i8 1, i8* %b, align 1
+  ret void
+}
+
 declare void @llvm.assume(i1)
+declare void @llvm.experimental.guard(i1, ...)
Index: lib/Analysis/AliasSetTracker.cpp
===================================================================
--- lib/Analysis/AliasSetTracker.cpp
+++ lib/Analysis/AliasSetTracker.cpp
@@ -24,6 +24,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/AtomicOrdering.h"
@@ -169,7 +170,11 @@
     addRef();
   UnknownInsts.emplace_back(I);
 
-  if (!I->mayWriteToMemory()) {
+  // Some intrinsics are marked as modifying memory, but don't actually do it.
+  using namespace PatternMatch;
+  bool MayWriteMemory = I->mayWriteToMemory() &&
+                        !match(I, m_Intrinsic<Intrinsic::experimental_guard>());
+  if (!MayWriteMemory) {
     Alias = SetMayAlias;
     Access |= RefAccess;
     return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50497.160058.patch
Type: text/x-patch
Size: 3160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180810/8fe9dd41/attachment.bin>


More information about the llvm-commits mailing list