This is an archive of the discontinued LLVM Phabricator instance.

[mips] [IAS] Restore STI.FeatureBits in .set pop.
ClosedPublic

Authored by tomatabacu on Apr 21 2015, 9:33 AM.

Details

Summary

Only restoring AvailableFeatures is not enough and will lead to buggy behaviour.
For example, if we have a feature enabled and we ".set pop", the next time we try
to ".set" that feature nothing will happen because the "!(STI.getFeatureBits()[Feature])"
check will be false, because we didn't restore STI.FeatureBits.

In order to fix this, we need to make MipsAssemblerOptions remember the STI.FeatureBits
instead of the AvailableFeatures and then regenerate AvailableFeatures each time we ".set pop".
This is because, AFAIK, there is no way to convert from AvailableFeatures back to STI.FeatureBits,
but the reverse is possible by using ComputeAvailableFeatures(STI.FeatureBits).

I also moved the updating of AssemblerOptions inside the "if" statement in
setFeatureBits() and clearFeatureBits(), as there is no reason to update if
nothing changes.

Diff Detail

Event Timeline

tomatabacu updated this revision to Diff 24139.Apr 21 2015, 9:33 AM
tomatabacu retitled this revision from to [mips] [IAS] Restore STI.FeatureBits in .set pop..
tomatabacu updated this object.
tomatabacu edited the test plan for this revision. (Show Details)
tomatabacu added a reviewer: dsanders.
tomatabacu added a subscriber: Unknown Object (MLST).
dsanders accepted this revision.Jun 1 2015, 6:01 AM
dsanders edited edge metadata.

LGTM with an extended test case to cover '.set pop' enabling a feature that was indirectly disabled inside a .set push/pop region.

test/MC/Mips/set-push-pop-directives.s
70

We ought to add a test like:

.set msa
.set push
.set mips32 # MSA not available in MIPS32
addvi.b $w1, $w2, 1 # CHECK: :[[@LINE-1]]:5: error: instruction requires a CPU feature not currently enabled
.set pop
addvi.b $w1, $w2, 1 # CHECK-NOT: :[[@LINE-1]]:5: error: instruction requires a CPU feature not currently enabled
This revision is now accepted and ready to land.Jun 1 2015, 6:01 AM
tomatabacu added inline comments.Jun 1 2015, 8:41 AM
test/MC/Mips/set-push-pop-directives.s
70

In GAS (and the IAS) ".set mips32" does not turn off MSA.
So there are no errors in this case, but GAS does emit warnings for inappropriate option combos (including MIPS32 and MSA).

These warnings are not implemented in the IAS at the moment.
They can be added in a separate patch, so I don't think they should block this patch.

dsanders added inline comments.Jun 1 2015, 9:03 AM
test/MC/Mips/set-push-pop-directives.s
70

MSA was only used as a convenient example. There should be other features bits that can be used to test that indirectly disabled features become enabled again after a .set pop.

In GAS (and the IAS) ".set mips32" does not turn off MSA.
So there are no errors in this case, but GAS does emit warnings for inappropriate option combos (including MIPS32 and MSA).

It should emit a diagnostic of some kind. It's not valid to use MSA with MIPS32 or earlier.

Note that the MSA feature is technically still enabled after the '.set mips32' but using MSA instructions is invalid (and should emit errors or warnings) until the '.set pop' restores the ISA to MIPS32r2.

tomatabacu updated this revision to Diff 27116.Jun 4 2015, 7:16 AM
tomatabacu edited edge metadata.

Added requested test case.
Rebased.
Had to make additional changes because of rL238192.

Added Michael Kuperstein as a reviewer because of changes related to his recent STI.FeatureBits work.

LGTM

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
46

Nit: Space goes before the '&' rather than after.

74

Nit: Here too.

tomatabacu updated this revision to Diff 27119.Jun 4 2015, 7:57 AM

Addressed spacing nits.

Waiting for Michael Kuperstein's approval.

Waiting for Michael Kuperstein's approval.

I don't think there's a need for Michael to explicitly LGTM this patch. One LGTM is usually sufficient and the common-code part of the change is just a formatting nit and adding a const.

tomatabacu updated this object.Jun 5 2015, 2:31 AM
tomatabacu closed this revision.Jun 5 2015, 4:52 AM
mkuper edited edge metadata.Jun 7 2015, 12:15 AM

Sorry for the latency, I was away for a few days.
Anyway, the target-independent part LGTM. The const really should have been there to begin with, thanks! :-)