This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Remove a dead ADD during the creation of TBBs
ClosedPublic

Authored by dmgreen on Mar 27 2017, 4:29 AM.

Details

Summary

During the optimisation of jump tables in the constant island pass,
an extra ADD could be left over, now dead but not removed.

Diff Detail

Event Timeline

dmgreen created this revision.Mar 27 2017, 4:29 AM
rengolin added inline comments.Apr 3 2017, 4:12 AM
lib/Target/ARM/ARMConstantIslandPass.cpp
2033

I'm confused. This means the else part will only execute one iteration after the add is detected.

Assuming ADD is never the last instruction (because the last is JumpMI), this should be ok, but I'm not sure why it's necessary, and it makes the code flow harder to understand.

Also, if there are multiple adds, this would overwrite the RemovableAdd pointer *before* it was sure the new ADD can be removed.

I'd make the whole iteration in one go, on a local pointer, and only update the higher scope pointer once the add is really the one we're looking for.

Would it be an error if we find two adds in the right condition?

dmgreen updated this revision to Diff 94029.Apr 4 2017, 3:10 AM

Hello, thanks for the suggestions.

The idea behind the loop is to find the last ADD that sets EntryReg (the register that the JT uses), providing EntryReg is not used or def'd between the ADD and the JT. I've split it up into two loops to make it more parsable. This is in a way just an attempt to improve preserveBaseRegister above, but when I tried to implement this in there it came out as a bit of a mess, and was no longer just doing "Preserve Base Register" stuff. Apparently the new function wasn't much better though!

Let me know what you think, cheers
Dave

rengolin accepted this revision.Apr 5 2017, 7:49 AM

Much clearer. Thanks! LGTM.

This revision is now accepted and ready to land.Apr 5 2017, 7:49 AM
This revision was automatically updated to reflect the committed changes.