[PATCH] D50861: [AST] Mark invariant.starts as being readonly

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 16 13:29:46 PDT 2018


reames created this revision.
reames added reviewers: mkazantsev, anna, skatkov, hfinkel.
Herald added subscribers: llvm-commits, bollu, mcrosier.

These intrinsics are modelled as writing for control flow purposes, but they don't actually write to any location.  Marking these - as we did for guards - allows LICM to hoist loads out of loops containing invariant.starts.


Repository:
  rL LLVM

https://reviews.llvm.org/D50861

Files:
  lib/Analysis/AliasSetTracker.cpp
  test/Transforms/LICM/invariant.start.ll


Index: test/Transforms/LICM/invariant.start.ll
===================================================================
--- test/Transforms/LICM/invariant.start.ll
+++ test/Transforms/LICM/invariant.start.ll
@@ -1,13 +1,13 @@
 ; RUN: opt -licm -basicaa < %s -S | FileCheck %s
 ; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' < %s -S | FileCheck %s
 
-; TODO: should be able to hoist both load and invariant.start
+; TODO: should be able to hoist the invariant.start
 define void @test1(i1 %cond, i32* %ptr) {
 ; CHECK-LABEL: @test1(
 ; CHECK-LABEL: entry:
+; CHECK: %val = load i32, i32* %ptr
 ; CHECK-LABEL: loop:
 ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
-; CHECK: %val = load i32, i32* %ptr
 
 entry:
   br label %loop
@@ -20,14 +20,13 @@
   br label %loop
 }
 
-;; TODO: despite the loop varying invariant.start, we should be
-;; able to hoist the load
+;; despite the loop varying invariant.start, we can hoist the load
 define void @test2(i1 %cond, i32* %ptr) {
 ; CHECK-LABEL: @test2(
 ; CHECK-LABEL: entry:
+; CHECK: %val = load i32, i32* %ptr
 ; CHECK-LABEL: loop:
 ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %piv)
-; CHECK: %val = load i32, i32* %ptr
   
 entry:
   br label %loop
@@ -41,13 +40,15 @@
   br label %loop
 }
 
-; Should be able to hoist since store doesn't alias
+;; can hoist the load since the store doesn't alias -- due to
+;; the unknown instruction handling, the store ends up in a separate
+;; aliasing set
 define void @test3(i1 %cond, i32* %ptr) {
 ; CHECK-LABEL: @test3(
 ; CHECK-LABEL: entry:
+; CHECK: %val = load i32, i32* %ptr
 ; CHECK-LABEL: loop:
 ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
-; CHECK: %val = load i32, i32* %ptr
 
 entry:
   br label %loop
@@ -85,20 +86,21 @@
 }
 
 ; don't try to reason about scopes
+;; FIXME: not actually testing scopes case yet
 define void @test5(i1 %cond, i32* %ptr) {
 ; CHECK-LABEL: @test5(
 ; CHECK-LABEL: entry:
+; CHECK: %val = load i32, i32* %ptr
 ; CHECK-LABEL: loop:
-; CHECK:   store i32 0, i32* %ptr
 ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
-; CHECK: %val = load i32, i32* %ptr
 
 entry:
   br label %loop
 
 loop:
   %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
-  store i32 0, i32* %ptr
+  %p2 = getelementptr i32, i32* %ptr, i32 1
+  store i32 0, i32* %p2
   %scope = call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
   %val = load i32, i32* %ptr
 ;;  NOTE: despite being correct syntax, uncommenting this line causes
Index: lib/Analysis/AliasSetTracker.cpp
===================================================================
--- lib/Analysis/AliasSetTracker.cpp
+++ lib/Analysis/AliasSetTracker.cpp
@@ -174,7 +174,8 @@
   // but don't actually modify any specific memory location.
   using namespace PatternMatch;
   bool MayWriteMemory = I->mayWriteToMemory() &&
-                        !match(I, m_Intrinsic<Intrinsic::experimental_guard>());
+    !match(I, m_Intrinsic<Intrinsic::experimental_guard>()) &&
+    !(I->use_empty() && match(I, m_Intrinsic<Intrinsic::invariant_start>()));
   if (!MayWriteMemory) {
     Alias = SetMayAlias;
     Access |= RefAccess;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50861.161100.patch
Type: text/x-patch
Size: 3231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180816/b6746db2/attachment.bin>


More information about the llvm-commits mailing list