[llvm] 04a2d50 - [PPC] Use getSignedConstant() for frame index offset
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 28 01:49:57 PST 2024
Author: Nikita Popov
Date: 2024-11-28T10:49:45+01:00
New Revision: 04a2d50efd668b752718f90811a7c628bfa761d7
URL: https://github.com/llvm/llvm-project/commit/04a2d50efd668b752718f90811a7c628bfa761d7
DIFF: https://github.com/llvm/llvm-project/commit/04a2d50efd668b752718f90811a7c628bfa761d7.diff
LOG: [PPC] Use getSignedConstant() for frame index offset
The offset is signed. Fixes assertion failure reported at:
https://github.com/llvm/llvm-project/pull/117558#issuecomment-2504413074
Added:
llvm/test/CodeGen/PowerPC/frameindex-negative-offset.ll
Modified:
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
index 4706051e601569..2475b8ad11f10a 100644
--- a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -193,8 +193,8 @@ namespace {
}
/// getSmallIPtrImm - Return a target constant of pointer type.
- inline SDValue getSmallIPtrImm(uint64_t Imm, const SDLoc &dl) {
- return CurDAG->getTargetConstant(
+ inline SDValue getSmallIPtrImm(int64_t Imm, const SDLoc &dl) {
+ return CurDAG->getSignedTargetConstant(
Imm, dl, PPCLowering->getPointerTy(CurDAG->getDataLayout()));
}
@@ -207,7 +207,7 @@ namespace {
/// base register. Return the virtual register that holds this value.
SDNode *getGlobalBaseReg();
- void selectFrameIndex(SDNode *SN, SDNode *N, uint64_t Offset = 0);
+ void selectFrameIndex(SDNode *SN, SDNode *N, int64_t Offset = 0);
// Select - Convert the specified operand from a target-independent to a
// target-specific node if it hasn't already been changed.
@@ -639,7 +639,7 @@ static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
&& isInt32Immediate(N->getOperand(1).getNode(), Imm);
}
-void PPCDAGToDAGISel::selectFrameIndex(SDNode *SN, SDNode *N, uint64_t Offset) {
+void PPCDAGToDAGISel::selectFrameIndex(SDNode *SN, SDNode *N, int64_t Offset) {
SDLoc dl(SN);
int FI = cast<FrameIndexSDNode>(N)->getIndex();
SDValue TFI = CurDAG->getTargetFrameIndex(FI, N->getValueType(0));
diff --git a/llvm/test/CodeGen/PowerPC/frameindex-negative-offset.ll b/llvm/test/CodeGen/PowerPC/frameindex-negative-offset.ll
new file mode 100644
index 00000000000000..c2208bba31aefd
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/frameindex-negative-offset.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=powerpc-unknown-linux-gnu < %s | FileCheck %s
+
+define ptr @test() nounwind {
+; CHECK-LABEL: test:
+; CHECK: # %bb.0:
+; CHECK-NEXT: stwu 1, -16(1)
+; CHECK-NEXT: addi 3, 1, 10
+; CHECK-NEXT: addi 1, 1, 16
+; CHECK-NEXT: blr
+ %alloca = alloca i32
+ %gep = getelementptr i8, ptr %alloca, i32 -2
+ ret ptr %gep
+}
More information about the llvm-commits
mailing list