[llvm] 7f28b4d - [LICM] Bail if checking a global/constant for invariant.start

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 4 14:14:32 PDT 2021


Author: Arthur Eubanks
Date: 2021-10-04T14:14:25-07:00
New Revision: 7f28b4d5b7a5f3581dbdba0ee8936b519034ae65

URL: https://github.com/llvm/llvm-project/commit/7f28b4d5b7a5f3581dbdba0ee8936b519034ae65
DIFF: https://github.com/llvm/llvm-project/commit/7f28b4d5b7a5f3581dbdba0ee8936b519034ae65.diff

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

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.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D111098

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index de6070405969..b8a0f86d7c26 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1068,6 +1068,10 @@ static bool isLoadInvariantInLoop(LoadInst *LI, DominatorTree *DT,
       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

diff  --git a/llvm/test/Transforms/LICM/hoisting.ll b/llvm/test/Transforms/LICM/hoisting.ll
index c77b1d62397c..1080f2a3ac4f 100644
--- a/llvm/test/Transforms/LICM/hoisting.ll
+++ b/llvm/test/Transforms/LICM/hoisting.ll
@@ -602,16 +602,16 @@ declare void @g(i1)
 
 @a = external global i8
 
-; FIXME: Don't hoist invariant loads of globals.
+; FIXME: Support hoisting invariant loads of globals.
 define void @test_fence6() {
 ; 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]]
 ;


        


More information about the llvm-commits mailing list