Skip to content

Commit 39edac2

Browse files
committed
[RISCV][GISel] Fix incorrect call to getGlobalAddress in selectGlobalValue.
RISCVII::MO_HI was being passed to the offset argument instead of the flags argument. Adjust some other calls to not pass an explicit 0 to the offset argument since it already has a default value of 0.
1 parent d0f6825 commit 39edac2

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ bool RISCVInstructionSelector::selectGlobalValue(
603603
// Use PC-relative addressing to access the symbol. This generates the
604604
// pattern (PseudoLLA sym), which expands to (addi (auipc %pcrel_hi(sym))
605605
// %pcrel_lo(auipc)).
606-
Result = MIB.buildInstr(RISCV::PseudoLLA, {DefReg}, {})
607-
.addGlobalAddress(GV, 0);
606+
Result =
607+
MIB.buildInstr(RISCV::PseudoLLA, {DefReg}, {}).addGlobalAddress(GV);
608608
} else {
609609
// Use PC-relative addressing to access the GOT for this symbol, then
610610
// load the address from the GOT. This generates the pattern (PseudoLGA
@@ -618,7 +618,7 @@ bool RISCVInstructionSelector::selectGlobalValue(
618618
DefTy, Align(DefTy.getSizeInBits() / 8));
619619

620620
Result = MIB.buildInstr(RISCV::PseudoLGA, {DefReg}, {})
621-
.addGlobalAddress(GV, 0)
621+
.addGlobalAddress(GV)
622622
.addMemOperand(MemOp);
623623
}
624624

@@ -641,7 +641,7 @@ bool RISCVInstructionSelector::selectGlobalValue(
641641
// (lui %hi(sym)) %lo(sym)).
642642
Register AddrHiDest = MRI.createVirtualRegister(&RISCV::GPRRegClass);
643643
MachineInstr *AddrHi = MIB.buildInstr(RISCV::LUI, {AddrHiDest}, {})
644-
.addGlobalAddress(GV, RISCVII::MO_HI);
644+
.addGlobalAddress(GV, 0, RISCVII::MO_HI);
645645

646646
if (!constrainSelectedInstRegOperands(*AddrHi, TII, TRI, RBI))
647647
return false;
@@ -673,14 +673,14 @@ bool RISCVInstructionSelector::selectGlobalValue(
673673
DefTy, Align(DefTy.getSizeInBits() / 8));
674674

675675
Result = MIB.buildInstr(RISCV::PseudoLGA, {DefReg}, {})
676-
.addGlobalAddress(GV, 0)
676+
.addGlobalAddress(GV)
677677
.addMemOperand(MemOp);
678678
} else {
679679
// Generate a sequence for accessing addresses within any 2GiB range
680680
// within the address space. This generates the pattern (PseudoLLA sym),
681681
// which expands to (addi (auipc %pcrel_hi(sym)) %pcrel_lo(auipc)).
682-
Result = MIB.buildInstr(RISCV::PseudoLLA, {DefReg}, {})
683-
.addGlobalAddress(GV, 0);
682+
Result =
683+
MIB.buildInstr(RISCV::PseudoLLA, {DefReg}, {}).addGlobalAddress(GV);
684684
}
685685

686686
if (!constrainSelectedInstRegOperands(*Result, TII, TRI, RBI))

llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/global-value32.mir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ body: |
4747
; RV32-NOPIE-TAG-NEXT: PseudoRET implicit $x10
4848
;
4949
; RV32-SMALL-NOPIE-NOTAG-LABEL: name: global_addr
50-
; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI @x + 4
50+
; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @x
5151
; RV32-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @x
5252
; RV32-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
5353
; RV32-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
@@ -80,7 +80,7 @@ body: |
8080
; RV32-NOPIE-TAG-NEXT: PseudoRET implicit $x10
8181
;
8282
; RV32-SMALL-NOPIE-NOTAG-LABEL: name: extern_weak_global_addr
83-
; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI @y + 4
83+
; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @y
8484
; RV32-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @y
8585
; RV32-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
8686
; RV32-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
@@ -113,7 +113,7 @@ body: |
113113
; RV32-NOPIE-TAG-NEXT: PseudoRET implicit $x10
114114
;
115115
; RV32-SMALL-NOPIE-NOTAG-LABEL: name: local_global_addr
116-
; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI @z + 4
116+
; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @z
117117
; RV32-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @z
118118
; RV32-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
119119
; RV32-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10

llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/global-value64.mir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ body: |
4646
; RV64-NOPIE-TAG-NEXT: PseudoRET implicit $x10
4747
;
4848
; RV64-SMALL-NOPIE-NOTAG-LABEL: name: global_addr
49-
; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI @x + 4
49+
; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @x
5050
; RV64-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @x
5151
; RV64-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
5252
; RV64-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
@@ -79,7 +79,7 @@ body: |
7979
; RV64-NOPIE-TAG-NEXT: PseudoRET implicit $x10
8080
;
8181
; RV64-SMALL-NOPIE-NOTAG-LABEL: name: extern_weak_global_addr
82-
; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI @y + 4
82+
; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @y
8383
; RV64-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @y
8484
; RV64-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
8585
; RV64-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
@@ -112,7 +112,7 @@ body: |
112112
; RV64-NOPIE-TAG-NEXT: PseudoRET implicit $x10
113113
;
114114
; RV64-SMALL-NOPIE-NOTAG-LABEL: name: local_global_addr
115-
; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI @z + 4
115+
; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @z
116116
; RV64-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @z
117117
; RV64-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
118118
; RV64-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10

0 commit comments

Comments
 (0)