Skip to content

Commit 0c47628

Browse files
committed
Re-commit "[RISCV] Properly support RISCVISD::LLA in getTargetConstantFromLoad. (#145112)"
With proper co-author. Original message: We need to pass the operand of LLA to GetSupportedConstantPool. This replaces #142292 with test from there added as a pre-commit for both medlow and pic. Co-authored-by: Carl Nettelblad carl.nettelblad@rapidity-space.com
1 parent fc36e47 commit 0c47628

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21062,7 +21062,7 @@ RISCVTargetLowering::getTargetConstantFromLoad(LoadSDNode *Ld) const {
2106221062

2106321063
// Simple case, LLA.
2106421064
if (Ptr.getOpcode() == RISCVISD::LLA) {
21065-
auto *CNode = GetSupportedConstantPool(Ptr);
21065+
auto *CNode = GetSupportedConstantPool(Ptr.getOperand(0));
2106621066
if (!CNode || CNode->getTargetFlags() != 0)
2106721067
return nullptr;
2106821068

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -O0 -mtriple=riscv64 -mattr=+m | FileCheck %s --check-prefix=NOPIC
3+
; RUN: llc < %s -O0 -mtriple=riscv64 -mattr=+m -relocation-model=pic | FileCheck %s --check-prefix=PIC
4+
5+
define i64 @test(i32 noundef signext %c, i32 noundef signext %d) {
6+
; NOPIC-LABEL: test:
7+
; NOPIC: # %bb.0: # %entry
8+
; NOPIC-NEXT: # kill: def $x11 killed $x10
9+
; NOPIC-NEXT: slli a0, a0, 32
10+
; NOPIC-NEXT: srli a1, a0, 32
11+
; NOPIC-NEXT: lui a0, %hi(.LCPI0_0)
12+
; NOPIC-NEXT: ld a0, %lo(.LCPI0_0)(a0)
13+
; NOPIC-NEXT: mul a0, a1, a0
14+
; NOPIC-NEXT: addi a0, a0, 127
15+
; NOPIC-NEXT: mul a0, a1, a0
16+
; NOPIC-NEXT: lui a2, %hi(.LCPI0_1)
17+
; NOPIC-NEXT: ld a2, %lo(.LCPI0_1)(a2)
18+
; NOPIC-NEXT: mul a0, a0, a2
19+
; NOPIC-NEXT: add a0, a0, a1
20+
; NOPIC-NEXT: lui a1, 1015920
21+
; NOPIC-NEXT: addi a1, a1, 1541
22+
; NOPIC-NEXT: slli a1, a1, 16
23+
; NOPIC-NEXT: addi a1, a1, 1027
24+
; NOPIC-NEXT: slli a1, a1, 20
25+
; NOPIC-NEXT: add a0, a0, a1
26+
; NOPIC-NEXT: ret
27+
;
28+
; PIC-LABEL: test:
29+
; PIC: # %bb.0: # %entry
30+
; PIC-NEXT: # kill: def $x11 killed $x10
31+
; PIC-NEXT: slli a0, a0, 32
32+
; PIC-NEXT: srli a1, a0, 32
33+
; PIC-NEXT: .Lpcrel_hi0:
34+
; PIC-NEXT: auipc a0, %pcrel_hi(.LCPI0_0)
35+
; PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi0)
36+
; PIC-NEXT: ld a0, 0(a0)
37+
; PIC-NEXT: mul a0, a1, a0
38+
; PIC-NEXT: addi a0, a0, 127
39+
; PIC-NEXT: mul a0, a1, a0
40+
; PIC-NEXT: .Lpcrel_hi1:
41+
; PIC-NEXT: auipc a2, %pcrel_hi(.LCPI0_1)
42+
; PIC-NEXT: addi a2, a2, %pcrel_lo(.Lpcrel_hi1)
43+
; PIC-NEXT: ld a2, 0(a2)
44+
; PIC-NEXT: mul a0, a0, a2
45+
; PIC-NEXT: add a0, a0, a1
46+
; PIC-NEXT: lui a1, 1015920
47+
; PIC-NEXT: addi a1, a1, 1541
48+
; PIC-NEXT: slli a1, a1, 16
49+
; PIC-NEXT: addi a1, a1, 1027
50+
; PIC-NEXT: slli a1, a1, 20
51+
; PIC-NEXT: add a0, a0, a1
52+
; PIC-NEXT: ret
53+
entry:
54+
%or1 = or i64 -9191740941672644608, 4096
55+
%or2 = or i64 -9191740941672644608, 8192
56+
%or3 = or i64 -9191740941672644608, 16384
57+
%conv = zext i32 %c to i64
58+
%donv = zext i32 %d to i64
59+
%3 = mul i64 %or1, %conv
60+
%4 = mul i64 %or2, %donv
61+
%5 = mul i64 %or3, %conv
62+
%6 = add i64 %3, %4
63+
%7 = add i64 %6, %5
64+
%8 = or i64 %5, 127
65+
%9 = mul i64 %3, %8
66+
%add = add i64 -9191740941672644608, %9
67+
%add2 = add i64 %add, %conv
68+
ret i64 %add2
69+
}

0 commit comments

Comments
 (0)