[PATCH] D111098: [LICM] Bail if checking a global/constant for invariant.start

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 4 13:48:51 PDT 2021


aeubanks created this revision.
Herald added subscribers: asbirlea, hiraditya.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When we check if a load is loop invariant by finding a dominating
invariant.start call, we strip bitcasts until we get to an i8* Value,
and look for an invariant.start use of the i8* Value.

We may accidentally end up at an i8 global and look at a global's uses,
which we shouldn't do in a loop pass. Although we could make this
logic work with globals, that's not currently intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111098

Files:
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/test/Transforms/LICM/hoisting.ll


Index: llvm/test/Transforms/LICM/hoisting.ll
===================================================================
--- llvm/test/Transforms/LICM/hoisting.ll
+++ llvm/test/Transforms/LICM/hoisting.ll
@@ -607,11 +607,11 @@
 ; CHECK-LABEL: @test_fence6(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[I:%.*]] = call {}* @llvm.invariant.start.p0i8(i64 1, i8* @a)
+; CHECK-NEXT:    br label [[F:%.*]]
+; CHECK:       f:
 ; CHECK-NEXT:    [[TMP0:%.*]] = load i8, i8* @a, align 1
 ; CHECK-NEXT:    [[TMP1:%.*]] = and i8 [[TMP0]], 0
 ; CHECK-NEXT:    [[T:%.*]] = icmp eq i8 [[TMP1]], 0
-; CHECK-NEXT:    br label [[F:%.*]]
-; CHECK:       f:
 ; CHECK-NEXT:    tail call void @g(i1 [[T]])
 ; CHECK-NEXT:    br label [[F]]
 ;
Index: llvm/lib/Transforms/Scalar/LICM.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LICM.cpp
+++ llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1068,6 +1068,10 @@
       return false;
     Addr = BC->getOperand(0);
   }
+  // If we've ended up at a global/constant, bail. We shouldn't be looking at
+  // uselists for non-local Values in a loop pass.
+  if (isa<Constant>(Addr))
+    return false;
 
   unsigned UsesVisited = 0;
   // Traverse all uses of the load operand value, to see if invariant.start is


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111098.377027.patch
Type: text/x-patch
Size: 1270 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211004/4fa1f01b/attachment.bin>


More information about the llvm-commits mailing list