Skip to content

Commit 42fe7cc

Browse files
JonPssontstellar
authored andcommitted
[SystemZ] Bugfix for symbolic displacements.
Properly handle the case where only the second operand of e.g. an MVC instruction uses a fixup for the displacement. Reviewed By: Ulrich Weigand Differential Revision: https://reviews.llvm.org/D125982 (cherry picked from commit e547b04)
1 parent f45a01e commit 42fe7cc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class SystemZMCCodeEmitter : public MCCodeEmitter {
3737
const MCInstrInfo &MCII;
3838
MCContext &Ctx;
3939

40+
mutable unsigned MemOpsEmitted;
41+
4042
public:
4143
SystemZMCCodeEmitter(const MCInstrInfo &mcii, MCContext &ctx)
4244
: MCII(mcii), Ctx(ctx) {
@@ -165,6 +167,7 @@ encodeInstruction(const MCInst &MI, raw_ostream &OS,
165167
verifyInstructionPredicates(MI,
166168
computeAvailableFeatures(STI.getFeatureBits()));
167169

170+
MemOpsEmitted = 0;
168171
uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, STI);
169172
unsigned Size = MCII.get(MI.getOpcode()).getSize();
170173
// Big-endian insertion of Size bytes.
@@ -191,12 +194,14 @@ getDispOpValue(const MCInst &MI, unsigned OpNum,
191194
SmallVectorImpl<MCFixup> &Fixups,
192195
SystemZ::FixupKind Kind) const {
193196
const MCOperand &MO = MI.getOperand(OpNum);
194-
if (MO.isImm())
197+
if (MO.isImm()) {
198+
++MemOpsEmitted;
195199
return static_cast<uint64_t>(MO.getImm());
200+
}
196201
if (MO.isExpr()) {
197202
// All instructions follow the pattern where the first displacement has a
198203
// 2 bytes offset, and the second one 4 bytes.
199-
unsigned ByteOffs = Fixups.size() == 0 ? 2 : 4;
204+
unsigned ByteOffs = MemOpsEmitted++ == 0 ? 2 : 4;
200205
Fixups.push_back(MCFixup::create(ByteOffs, MO.getExpr(), (MCFixupKind)Kind,
201206
MI.getLoc()));
202207
assert(Fixups.size() <= 2 && "More than two memory operands in MI?");

llvm/test/MC/SystemZ/fixups.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@
287287
.align 16
288288
vgeg %v0, src(%v0,%r1), 0
289289

290+
## Fixup for second operand only
291+
# CHECK: mvc 32(8,%r0), src # encoding: [0xd2,0x07,0x00,0x20,0b0000AAAA,A]
292+
# CHECK-NEXT: # fixup A - offset: 4, value: src, kind: FK_390_12
293+
.align 16
294+
mvc 32(8,%r0),src
290295

291296
# Data relocs
292297
# llvm-mc does not show any "encoding" string for data, so we just check the relocs

0 commit comments

Comments
 (0)