[llvm] [XCore] Use getPtrAdd() instead of getGetElementPtr() (NFC) (PR #222017)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 07:46:40 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/222017

This was creating an i8 getelementptr, which is exactly what
ptradd is.

>From 45eaa2dbf88918ae9cdb60bd696d317f2a180856 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 8 Sep 2026 16:45:41 +0200
Subject: [PATCH] [XCore] Use getPtrAdd() instead of getGetElementPtr() (NFC)

This was creating an i8 getelementptr, which is exactly what
ptradd is.
---
 llvm/lib/Target/XCore/XCoreISelLowering.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/Target/XCore/XCoreISelLowering.cpp b/llvm/lib/Target/XCore/XCoreISelLowering.cpp
index c3cbb4b4752d2..8b193cfab7a74 100644
--- a/llvm/lib/Target/XCore/XCoreISelLowering.cpp
+++ b/llvm/lib/Target/XCore/XCoreISelLowering.cpp
@@ -264,8 +264,7 @@ LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
     // Ideally we would not fold in offset with an index <= 11.
     Type *Ty = Type::getInt32Ty(*DAG.getContext());
     Constant *Idx = ConstantInt::get(Ty, Offset);
-    Constant *GAI = ConstantExpr::getGetElementPtr(
-        Type::getInt8Ty(*DAG.getContext()), const_cast<GlobalValue *>(GV), Idx);
+    Constant *GAI = ConstantExpr::getPtrAdd(const_cast<GlobalValue *>(GV), Idx);
     SDValue CP = DAG.getConstantPool(GAI, MVT::i32);
     return DAG.getLoad(getPointerTy(DAG.getDataLayout()), DL,
                        DAG.getEntryNode(), CP, MachinePointerInfo());



More information about the llvm-commits mailing list