@@ -780,7 +780,6 @@ bool RISCVInstructionSelector::selectAddr(MachineInstr &MI,
780
780
781
781
Register DefReg = MI.getOperand (0 ).getReg ();
782
782
const LLT DefTy = MRI.getType (DefReg);
783
- MachineInstr *Result = nullptr ;
784
783
785
784
// When HWASAN is used and tagging of global variables is enabled
786
785
// they should be accessed via the GOT, since the tagged address of a global
@@ -791,25 +790,25 @@ bool RISCVInstructionSelector::selectAddr(MachineInstr &MI,
791
790
// Use PC-relative addressing to access the symbol. This generates the
792
791
// pattern (PseudoLLA sym), which expands to (addi (auipc %pcrel_hi(sym))
793
792
// %pcrel_lo(auipc)).
794
- Result =
795
- MIB.buildInstr (RISCV::PseudoLLA, {DefReg}, {}).addDisp (DispMO, 0 );
796
- } else {
797
- // Use PC-relative addressing to access the GOT for this symbol, then
798
- // load the address from the GOT. This generates the pattern (PseudoLGA
799
- // sym), which expands to (ld (addi (auipc %got_pcrel_hi(sym))
800
- // %pcrel_lo(auipc))).
801
- MachineFunction &MF = *MI.getParent ()->getParent ();
802
- MachineMemOperand *MemOp = MF.getMachineMemOperand (
803
- MachinePointerInfo::getGOT (MF),
804
- MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
805
- MachineMemOperand::MOInvariant,
806
- DefTy, Align (DefTy.getSizeInBits () / 8 ));
807
-
808
- Result = MIB.buildInstr (RISCV::PseudoLGA, {DefReg}, {})
809
- .addDisp (DispMO, 0 )
810
- .addMemOperand (MemOp);
793
+ MI.setDesc (TII.get (RISCV::PseudoLLA));
794
+ return constrainSelectedInstRegOperands (MI, TII, TRI, RBI);
811
795
}
812
796
797
+ // Use PC-relative addressing to access the GOT for this symbol, then
798
+ // load the address from the GOT. This generates the pattern (PseudoLGA
799
+ // sym), which expands to (ld (addi (auipc %got_pcrel_hi(sym))
800
+ // %pcrel_lo(auipc))).
801
+ MachineFunction &MF = *MI.getParent ()->getParent ();
802
+ MachineMemOperand *MemOp = MF.getMachineMemOperand (
803
+ MachinePointerInfo::getGOT (MF),
804
+ MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
805
+ MachineMemOperand::MOInvariant,
806
+ DefTy, Align (DefTy.getSizeInBits () / 8 ));
807
+
808
+ auto Result = MIB.buildInstr (RISCV::PseudoLGA, {DefReg}, {})
809
+ .addDisp (DispMO, 0 )
810
+ .addMemOperand (MemOp);
811
+
813
812
if (!constrainSelectedInstRegOperands (*Result, TII, TRI, RBI))
814
813
return false ;
815
814
@@ -834,8 +833,8 @@ bool RISCVInstructionSelector::selectAddr(MachineInstr &MI,
834
833
if (!constrainSelectedInstRegOperands (*AddrHi, TII, TRI, RBI))
835
834
return false ;
836
835
837
- Result = MIB.buildInstr (RISCV::ADDI, {DefReg}, {AddrHiDest})
838
- .addDisp (DispMO, 0 , RISCVII::MO_LO);
836
+ auto Result = MIB.buildInstr (RISCV::ADDI, {DefReg}, {AddrHiDest})
837
+ .addDisp (DispMO, 0 , RISCVII::MO_LO);
839
838
840
839
if (!constrainSelectedInstRegOperands (*Result, TII, TRI, RBI))
841
840
return false ;
@@ -860,22 +859,22 @@ bool RISCVInstructionSelector::selectAddr(MachineInstr &MI,
860
859
MachineMemOperand::MOInvariant,
861
860
DefTy, Align (DefTy.getSizeInBits () / 8 ));
862
861
863
- Result = MIB.buildInstr (RISCV::PseudoLGA, {DefReg}, {})
864
- .addDisp (DispMO, 0 )
865
- .addMemOperand (MemOp);
866
- } else {
867
- // Generate a sequence for accessing addresses within any 2GiB range
868
- // within the address space. This generates the pattern (PseudoLLA sym),
869
- // which expands to (addi (auipc %pcrel_hi(sym)) %pcrel_lo(auipc)).
870
- Result =
871
- MIB.buildInstr (RISCV::PseudoLLA, {DefReg}, {}).addDisp (DispMO, 0 );
872
- }
862
+ auto Result = MIB.buildInstr (RISCV::PseudoLGA, {DefReg}, {})
863
+ .addDisp (DispMO, 0 )
864
+ .addMemOperand (MemOp);
873
865
874
- if (!constrainSelectedInstRegOperands (*Result, TII, TRI, RBI))
875
- return false ;
866
+ if (!constrainSelectedInstRegOperands (*Result, TII, TRI, RBI))
867
+ return false ;
876
868
877
- MI.eraseFromParent ();
878
- return true ;
869
+ MI.eraseFromParent ();
870
+ return true ;
871
+ }
872
+
873
+ // Generate a sequence for accessing addresses within any 2GiB range
874
+ // within the address space. This generates the pattern (PseudoLLA sym),
875
+ // which expands to (addi (auipc %pcrel_hi(sym)) %pcrel_lo(auipc)).
876
+ MI.setDesc (TII.get (RISCV::PseudoLLA));
877
+ return constrainSelectedInstRegOperands (MI, TII, TRI, RBI);
879
878
}
880
879
881
880
return false ;
0 commit comments