Skip to content

Commit

Permalink
[RISCV] Support uimm32 immediates in RISCVInstrInfo::movImm for RV32. (
Browse files Browse the repository at this point in the history
…#88464)

This allows us to support larger stack offsets for FrameLowering.

Fixes #88365.
  • Loading branch information
topperc committed Apr 12, 2024
1 parent 4dd20b0 commit 040efaf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
11 changes: 9 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,15 @@ void RISCVInstrInfo::movImm(MachineBasicBlock &MBB,
bool DstIsDead) const {
Register SrcReg = RISCV::X0;

if (!STI.is64Bit() && !isInt<32>(Val))
report_fatal_error("Should only materialize 32-bit constants for RV32");
// For RV32, allow a sign or unsigned 32 bit value.
if (!STI.is64Bit() && !isInt<32>(Val)) {
// If have a uimm32 it will still fit in a register so we can allow it.
if (!isUInt<32>(Val))
report_fatal_error("Should only materialize 32-bit constants for RV32");

// Sign extend for generateInstSeq.
Val = SignExtend64<32>(Val);
}

RISCVMatInt::InstSeq Seq = RISCVMatInt::generateInstSeq(Val, STI);
assert(!Seq.empty());
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/CodeGen/RISCV/pr88365.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
; RUN: llc < %s -mtriple=riscv32 | FileCheck %s

define void @foo() {
; CHECK-LABEL: foo:
; CHECK: # %bb.0:
; CHECK-NEXT: addi sp, sp, -2032
; CHECK-NEXT: .cfi_def_cfa_offset 2032
; CHECK-NEXT: sw ra, 2028(sp) # 4-byte Folded Spill
; CHECK-NEXT: .cfi_offset ra, -4
; CHECK-NEXT: li a0, -2048
; CHECK-NEXT: sub sp, sp, a0
; CHECK-NEXT: .cfi_def_cfa_offset -16
; CHECK-NEXT: addi a0, sp, 4
; CHECK-NEXT: call use
; CHECK-NEXT: li a0, -2048
; CHECK-NEXT: add sp, sp, a0
; CHECK-NEXT: lw ra, 2028(sp) # 4-byte Folded Reload
; CHECK-NEXT: addi sp, sp, 2032
; CHECK-NEXT: ret
%1 = alloca [1073741818 x i32], align 4
call void @use(ptr %1)
ret void
}

declare void @use(ptr)

0 comments on commit 040efaf

Please sign in to comment.