Skip to content

Commit 0b56cea

Browse files
author
git apple-llvm automerger
committed
Merge commit '040efafa9fef' from llvm.org/main into next
2 parents 77e4df9 + 040efaf commit 0b56cea

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,15 @@ void RISCVInstrInfo::movImm(MachineBasicBlock &MBB,
767767
bool DstIsDead) const {
768768
Register SrcReg = RISCV::X0;
769769

770-
if (!STI.is64Bit() && !isInt<32>(Val))
771-
report_fatal_error("Should only materialize 32-bit constants for RV32");
770+
// For RV32, allow a sign or unsigned 32 bit value.
771+
if (!STI.is64Bit() && !isInt<32>(Val)) {
772+
// If have a uimm32 it will still fit in a register so we can allow it.
773+
if (!isUInt<32>(Val))
774+
report_fatal_error("Should only materialize 32-bit constants for RV32");
775+
776+
// Sign extend for generateInstSeq.
777+
Val = SignExtend64<32>(Val);
778+
}
772779

773780
RISCVMatInt::InstSeq Seq = RISCVMatInt::generateInstSeq(Val, STI);
774781
assert(!Seq.empty());

llvm/test/CodeGen/RISCV/pr88365.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc < %s -mtriple=riscv32 | FileCheck %s
3+
4+
define void @foo() {
5+
; CHECK-LABEL: foo:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: addi sp, sp, -2032
8+
; CHECK-NEXT: .cfi_def_cfa_offset 2032
9+
; CHECK-NEXT: sw ra, 2028(sp) # 4-byte Folded Spill
10+
; CHECK-NEXT: .cfi_offset ra, -4
11+
; CHECK-NEXT: li a0, -2048
12+
; CHECK-NEXT: sub sp, sp, a0
13+
; CHECK-NEXT: .cfi_def_cfa_offset -16
14+
; CHECK-NEXT: addi a0, sp, 4
15+
; CHECK-NEXT: call use
16+
; CHECK-NEXT: li a0, -2048
17+
; CHECK-NEXT: add sp, sp, a0
18+
; CHECK-NEXT: lw ra, 2028(sp) # 4-byte Folded Reload
19+
; CHECK-NEXT: addi sp, sp, 2032
20+
; CHECK-NEXT: ret
21+
%1 = alloca [1073741818 x i32], align 4
22+
call void @use(ptr %1)
23+
ret void
24+
}
25+
26+
declare void @use(ptr)

0 commit comments

Comments
 (0)