[llvm] [PowerPC] Use getSignedTargetConstant in SelectOptimalAddrMode. (PR #127305)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 14 23:44:35 PST 2025


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/127305

Fixes #127298.

>From 847b5e2820b481ac96d77c2e855a5fe4fd6f760a Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Fri, 14 Feb 2025 23:42:13 -0800
Subject: [PATCH] [PowerPC] Use getSignedTargetConstant in
 SelectOptimalAddrMode.

Fixes #127298.
---
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 4 ++--
 llvm/test/CodeGen/PowerPC/pr127298.ll       | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/PowerPC/pr127298.ll

diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index f1195feea80e8..767d1ded8de3a 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -19110,8 +19110,8 @@ PPC::AddrMode PPCTargetLowering::SelectOptimalAddrMode(const SDNode *Parent,
         int32_t Addr = (int32_t)CNImm;
         // Otherwise, break this down into LIS + Disp.
         Disp = DAG.getSignedTargetConstant((int16_t)Addr, DL, MVT::i32);
-        Base =
-            DAG.getTargetConstant((Addr - (int16_t)Addr) >> 16, DL, MVT::i32);
+        Base = DAG.getSignedTargetConstant((Addr - (int16_t)Addr) >> 16, DL,
+                                           MVT::i32);
         uint32_t LIS = CNType == MVT::i32 ? PPC::LIS : PPC::LIS8;
         Base = SDValue(DAG.getMachineNode(LIS, DL, CNType, Base), 0);
         break;
diff --git a/llvm/test/CodeGen/PowerPC/pr127298.ll b/llvm/test/CodeGen/PowerPC/pr127298.ll
new file mode 100644
index 0000000000000..327b7c21d698c
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/pr127298.ll
@@ -0,0 +1,7 @@
+; RUN: llc < %s -mtriple=powerpc | FileCheck %s
+
+define void @foo() {
+Entry:
+  %0 = load volatile i8, ptr inttoptr (i32 -559038737 to ptr), align 1
+  ret void
+}



More information about the llvm-commits mailing list