[llvm] [SCEV] Simplify getElementSz using getLoadStore-helpers (NFC) (PR #222908)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 03:13:45 PDT 2026


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/222908

None

>From 590b06bae2f1987aca29d63721f401f5fb9d6242 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Fri, 11 Sep 2026 11:07:41 +0100
Subject: [PATCH] [SCEV] Simplify getElementSz using getLoadStore-helpers (NFC)

---
 llvm/lib/Analysis/ScalarEvolution.cpp | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 06f350fd2179b..85ee3848cbb5b 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -14026,20 +14026,12 @@ bool ScalarEvolution::containsErasedValue(const SCEV *S) const {
 
 /// Return the size of an element read or written by Inst.
 const SCEV *ScalarEvolution::getElementSize(Instruction *Inst) {
-  Type *Ty;
-  Type *PtrTy;
-  if (StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
-    Ty = Store->getValueOperand()->getType();
-    PtrTy = Store->getPointerOperandType();
-  } else if (LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
-    Ty = Load->getType();
-    PtrTy = Load->getPointerOperandType();
-  } else {
+  if (!isa<LoadInst, StoreInst>(Inst))
     return nullptr;
-  }
-
-  Type *ETy = getEffectiveSCEVType(PtrTy);
-  return getSizeOfExpr(ETy, Ty);
+  Type *Ty = getLoadStoreType(Inst);
+  Type *PtrTy =
+      getEffectiveSCEVType(getLoadStorePointerOperand(Inst)->getType());
+  return getSizeOfExpr(PtrTy, Ty);
 }
 
 //===----------------------------------------------------------------------===//



More information about the llvm-commits mailing list