This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Cleanup part of ARMBaseInstrInfo::optimizeCompareInstr (NFCI).
ClosedPublic

Authored by jgalenson on Jan 19 2018, 12:37 PM.

Diff Detail

Event Timeline

jgalenson created this revision.Jan 19 2018, 12:37 PM

I considered using reverse_iterator here, but I couldn't get something that looked clean to me, since I had to convert I and E and compare against E and the beginning of the block. I also considered splitting this loop into two, one that searches for SubAdd and one that checks for CPSR reads/writes, but that also seemed more complicated. I'd be open to suggestions on how to improve this further, though.

since I had to convert I and E and compare against E and the beginning of the block

You should be able to tell which of "I != B" or "I != E" is the important exit condition before you enter the loop. Either E and I are in the same block (so I != E will fail before I != B), or they're not in the same block (so I != E will always be true).

You should be able to tell which of "I != B" or "I != E" is the important exit condition before you enter the loop. Either E and I are in the same block (so I != E will fail before I != B), or they're not in the same block (so I != E will always be true).

Yes, that's exactly what I did, but the extra logic to do that comparison, convert them into a reverse iterator, and get the bounds conditions correct (we want to consider E and B, so that would be inclusive, and if we instead used rend() that would be exclusive) seemed more complicated to me.

efriedma added inline comments.Jan 19 2018, 1:03 PM
lib/Target/ARM/ARMBaseInstrInfo.cpp
2754

Maybe it would be more clear to write "if (I == E) break;" before this check?

jgalenson added inline comments.Jan 19 2018, 1:11 PM
lib/Target/ARM/ARMBaseInstrInfo.cpp
2754

Sure, I can do that, but it does re-introduce an early exit into the loop, which I remember you didn't like before.

This, by the way, is exactly why I considered splitting this into two loops, which is another possibility, although it seemed a bit more complicated (and less efficient) to me.

efriedma added inline comments.Jan 19 2018, 2:02 PM
lib/Target/ARM/ARMBaseInstrInfo.cpp
2754

An early break isn't always ideal, but I think it makes sense here; it has a similar meaning to the other break in the if (isRedundantFlagInstr... block.

jgalenson updated this revision to Diff 130691.Jan 19 2018, 2:13 PM
This revision is now accepted and ready to land.Jan 19 2018, 3:56 PM
This revision was automatically updated to reflect the committed changes.