This is an archive of the discontinued LLVM Phabricator instance.

Fix ARM's add->adr translations for expressions
ClosedPublic

Authored by joerg on Nov 21 2014, 2:44 AM.

Details

Summary

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.

Diff Detail

Event Timeline

joerg updated this revision to Diff 16476.Nov 21 2014, 2:44 AM
joerg retitled this revision from to Fix ARM's add->adr translations for expressions.
joerg updated this object.
joerg edited the test plan for this revision. (Show Details)
joerg added reviewers: t.p.northover, grosbach.
joerg set the repository for this revision to rL LLVM.
joerg added a subscriber: Unknown Object (MLST).
grosbach edited edge metadata.Nov 21 2014, 12:10 PM

Seems reasonable to me, but Tim will definitely have a better eye for the details than I.

t.p.northover edited edge metadata.Nov 21 2014, 1:34 PM

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);
joerg accepted this revision.Nov 21 2014, 2:41 PM
joerg added a reviewer: joerg.
This revision is now accepted and ready to land.Nov 21 2014, 2:41 PM
joerg closed this revision.Nov 21 2014, 2:41 PM