When transforming non-immediates from the PC-argument form of add to adr, PC needs to get added as expression base. At the same time, the magic offset 8 has to be specified too, otherwise the computed immediate is off.
Details
Details
Diff Detail
Diff Detail
Event Timeline
Comment Actions
Seems reasonable to me, but Tim will definitely have a better eye for the details than I.
Comment Actions
Hi Joerg,
I've convinced myself that it's probably for the best (a little concerned by the isImm() divergence, but it's certainly arguably the best option).
But I think the calculation & comment could be improved slightly:
lib/Target/ARM/AsmParser/ARMAsmParser.cpp | ||
---|---|---|
6489–6490 | This is slightly deeper than a fixup compensation, which suggests it's an LLVM implementation-detail. The +8 is there because for historical reasons whenever you read PC as a register in ARM mode you get "PC of start of current instruction + 8", but that's not what '.' means. So "lbl - (. + 8)" really is what you write to get the address of lbl in an add. The code is perhaps more naturally represented as: const MCExpr *InstPC = MCSymbolRefExpr::Create(Sym, ...); [...] const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8); const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr); |
This is slightly deeper than a fixup compensation, which suggests it's an LLVM implementation-detail.
The +8 is there because for historical reasons whenever you read PC as a register in ARM mode you get "PC of start of current instruction + 8", but that's not what '.' means. So "lbl - (. + 8)" really is what you write to get the address of lbl in an add. The code is perhaps more naturally represented as: