This is an archive of the discontinued LLVM Phabricator instance.

[mips] [IAS] Fix expansion of LASym with positive offset.
AbandonedPublic

Authored by tomatabacu on Apr 29 2015, 7:06 AM.

Details

Reviewers
dsanders
Summary

Instead of creating the MCSymbolRefExpr's manually, we can use evaluateRelocExpr().
This gives us the ability to correctly handle MCBinaryExpr's for LASym.

Diff Detail

Event Timeline

dsanders requested changes to this revision.May 19 2015, 7:23 AM
dsanders edited edge metadata.
dsanders added inline comments.
lib/Target/Mips/AsmParser/MipsAsmParser.cpp
2526–2527

Despite it's name, I don't think this is really evaluating expressions. It seems to be simplifying them.

2526–2585

This code seems suspicious. For example, the MCBinaryExpr path tries to apply the RelocStr to both sides of the operator but it's easy to think of cases where this is incorrect. For example %hi(symbol+1) is not equivalent to %hi(symbol) + %hi(1) when symbol==0. The former results in %hi(1) = 0 while the latter results in %hi(0) + %hi(1) = 1.

test/MC/Mips/mips-expansions.s
28–44

These look wrong to me. I'd expect the same expression inside both the %hi and %lo's like so:
lui $8, %hi(symbol+1)
ori $8, $8, %lo(symbol+1)
lui $8, %hi(symbol+32770)
ori $8, $8, %lo(symbol+32770)
lui $8, %hi(symbol+65538)
ori $8, $8, %lo(symbol+65538)
lui $8, %hi(symbol+1118481)
ori $8, $8, %lo(symbol+1118481)

This revision now requires changes to proceed.May 19 2015, 7:23 AM
tomatabacu added inline comments.May 26 2015, 7:14 AM
lib/Target/Mips/AsmParser/MipsAsmParser.cpp
2526–2585

It's true that this function needs to be revised a bit, but I don't think it should be a blocker for this patch, as long as the output is semantically equivalent to GAS' (see my reply to the comment below).

test/MC/Mips/mips-expansions.s
28–44

AFAICT the examples you give do not match GAS' output.
The expansions from the patch are closer to the ones from GAS, the only difference being that GAS uses ADDiu and we use ORi.

tomatabacu updated this revision to Diff 27507.Jun 11 2015, 8:19 AM
tomatabacu edited edge metadata.

Rebased (for Sean's convenience).

tomatabacu abandoned this revision.Jun 25 2015, 6:29 AM

Abandoned due to existing problems with evaluateRelocExpr().