[libc-commits] [libc] [LICM] Simplify isLoadInvariantInLoop given opaque pointers (PR #65597)
Björn Pettersson via libc-commits
libc-commits at lists.llvm.org
Fri Sep 8 09:08:36 PDT 2023
https://github.com/bjope updated https://github.com/llvm/llvm-project/pull/65597:
>From a7981549e35db066c4ff49f5597bcb42b8701af7 Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
Date: Thu, 7 Sep 2023 12:42:34 +0200
Subject: [PATCH] [LICM] Simplify isLoadInvariantInLoop given opaque pointers
Since we no longer support typed pointers in LLVM IR, the PtrASXTy
in isLoadInvariantInLoop was set to be equal to Addr->getType() (an
opaque ptr in the same address space). That made the loop looking
through bitcasts redundant.
---
llvm/lib/Transforms/Scalar/LICM.cpp | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 2d987b4defa49cb..92b73304a6c13ae 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1039,7 +1039,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
// invariant.start has no uses.
static bool isLoadInvariantInLoop(LoadInst *LI, DominatorTree *DT,
Loop *CurLoop) {
- Value *Addr = LI->getOperand(0);
+ Value *Addr = LI->getPointerOperand();
const DataLayout &DL = LI->getModule()->getDataLayout();
const TypeSize LocSizeInBits = DL.getTypeSizeInBits(LI->getType());
@@ -1055,21 +1055,6 @@ static bool isLoadInvariantInLoop(LoadInst *LI, DominatorTree *DT,
if (LocSizeInBits.isScalable())
return false;
- // if the type is ptr addrspace(x), we know this is the type of
- // llvm.invariant.start operand
- auto *PtrASXTy = PointerType::get(LI->getContext(),
- LI->getPointerAddressSpace());
- unsigned BitcastsVisited = 0;
- // Look through bitcasts until we reach the PtrASXTy type (this is
- // invariant.start operand type).
- // FIXME: We shouldn't really find such bitcasts with opaque pointers.
- while (Addr->getType() != PtrASXTy) {
- auto *BC = dyn_cast<BitCastInst>(Addr);
- // Avoid traversing high number of bitcast uses.
- if (++BitcastsVisited > MaxNumUsesTraversed || !BC)
- 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))
More information about the libc-commits
mailing list