Skip to content

Commit 9e687ae

Browse files
committed
[RISCV] Fix Compression with Symbols for Xqci
This adds more tests for emitting Xqci instructions with symbols, to check the case where the instruction has a symbol but may get compressed. Some of these tests were causing crashes before. This change then fixes the crashes, by changing the MCOperandPredicates, which are used for compression. This prevents compressing instructions with symbols when we have no way of applying the fixup to the compressed instruction, as is the case for CI-type instructions, but also for `qc.li` which takes a symbol with a specifier.
1 parent 7842e9e commit 9e687ae

File tree

6 files changed

+67
-7
lines changed

6 files changed

+67
-7
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "RISCVBaseInfo.h"
15+
#include "MCTargetDesc/RISCVMCAsmInfo.h"
16+
#include "llvm/MC/MCExpr.h"
1517
#include "llvm/MC/MCInst.h"
1618
#include "llvm/MC/MCRegisterInfo.h"
1719
#include "llvm/MC/MCSubtargetInfo.h"
20+
#include "llvm/Support/Casting.h"
1821
#include "llvm/Support/raw_ostream.h"
1922
#include "llvm/TargetParser/TargetParser.h"
2023
#include "llvm/TargetParser/Triple.h"

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def uimmlog2xlennonzero : RISCVOp, ImmLeaf<XLenVT, [{
3737
def simm6 : RISCVSImmLeafOp<6> {
3838
let MCOperandPredicate = [{
3939
int64_t Imm;
40-
if (MCOp.evaluateAsConstantImm(Imm))
41-
return isInt<6>(Imm);
42-
return MCOp.isBareSymbolRef();
40+
if (!MCOp.evaluateAsConstantImm(Imm))
41+
return false;
42+
return isInt<6>(Imm);
4343
}];
4444
}
4545

@@ -51,9 +51,9 @@ def simm6nonzero : RISCVOp,
5151
let OperandType = "OPERAND_SIMM6_NONZERO";
5252
let MCOperandPredicate = [{
5353
int64_t Imm;
54-
if (MCOp.evaluateAsConstantImm(Imm))
55-
return (Imm != 0) && isInt<6>(Imm);
56-
return MCOp.isBareSymbolRef();
54+
if (!MCOp.evaluateAsConstantImm(Imm))
55+
return false;
56+
return (Imm != 0) && isInt<6>(Imm);
5757
}];
5858
}
5959

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ def simm20_li : RISCVOp<XLenVT>,
146146
int64_t Imm;
147147
if (MCOp.evaluateAsConstantImm(Imm))
148148
return isInt<20>(Imm);
149-
return MCOp.isBareSymbolRef();
149+
150+
if (!MCOp.isExpr())
151+
return false;
152+
153+
return MCOp.getExpr()->getKind() == MCExpr::Specifier &&
154+
cast<MCSpecifierExpr>(MCOp.getExpr())->getSpecifier() == RISCV::S_QC_ABS20;
150155
}];
151156
}
152157

llvm/test/MC/RISCV/xqcibi-relocations.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ qc.e.bgeui s2, 24, same_section
8686

8787
.option norelax
8888

89+
## Enable compression/relaxation to check how symbols are handled.
90+
.option noexact
91+
.option relax
92+
93+
# ASM: qc.bnei t1, 10, undef
94+
# OBJ: qc.beqi t1, 0xa, 0x42 <same_section_extern+0x16>
95+
# OBJ-NEXT: j 0x3e <same_section_extern+0x12>
96+
# OBJ-NEXT: R_RISCV_JAL undef{{$}}
97+
qc.bnei t1, 10, undef
98+
99+
# ASM: qc.e.bgeui s0, 40, undef
100+
# OBJ-NEXT: qc.e.bltui s0, 0x28, 0x4c <same_section_extern+0x20>
101+
# OBJ-NEXT: j 0x48 <same_section_extern+0x1c>
102+
# OBJ-NEXT: R_RISCV_JAL undef{{$}}
103+
qc.e.bgeui s0, 40, undef
104+
89105
.section .text.second, "ax", @progbits
90106

91107
# ASM-LABEL: other_section:

llvm/test/MC/RISCV/xqcilb-relocations.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ qc.e.jal same_section
9494

9595
.option norelax
9696

97+
## Enable compression/relaxation to check how symbols are handled.
98+
.option noexact
99+
.option relax
100+
101+
qc.e.j undef
102+
# ASM: j undef
103+
# OBJ: qc.e.j 0x44 <same_section_extern+0x10>
104+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
105+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
106+
# OBJ-NEXT: R_RISCV_RELAX
107+
108+
qc.e.jal undef
109+
# ASM: jal undef
110+
# OBJ: qc.e.jal 0x4a <same_section_extern+0x16>
111+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
112+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
113+
# OBJ-NEXT: R_RISCV_RELAX
114+
97115
.section .text.other, "ax", @progbits
98116

99117
# ASM-LABEL: other_section:

llvm/test/MC/RISCV/xqcili-relocations.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ qc.e.li s1, undef
9999

100100
.option norelax
101101

102+
## Enable compression/relaxation to check how symbols are handled.
103+
.option noexact
104+
.option relax
105+
106+
# ASM: qc.li a1, %qc.abs20(undef)
107+
# OBJ-NEXT: qc.li a1, 0x0
108+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
109+
# OBJ-NEXT: R_RISCV_CUSTOM192 undef{{$}}
110+
# OBJ-NEXT: R_RISCV_RELAX
111+
qc.li a1, %qc.abs20(undef)
112+
113+
# ASM: qc.e.li a1, undef
114+
# OBJ-NEXT: qc.e.li a1, 0x0
115+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
116+
# OBJ-NEXT: R_RISCV_CUSTOM194 undef{{$}}
117+
# OBJ-NEXT: R_RISCV_RELAX
118+
qc.e.li a1, undef
119+
102120
.section .text.other, "ax", @progbits
103121

104122
# ASM-LABEL: other_section:

0 commit comments

Comments
 (0)