As noted in another review, this loop is confusing. This commit cleans it up somewhat.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
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.
lib/Target/ARM/ARMBaseInstrInfo.cpp | ||
---|---|---|
2754 ↗ | (On Diff #130674) | Maybe it would be more clear to write "if (I == E) break;" before this check? |
lib/Target/ARM/ARMBaseInstrInfo.cpp | ||
---|---|---|
2754 ↗ | (On Diff #130674) | 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. |
lib/Target/ARM/ARMBaseInstrInfo.cpp | ||
---|---|---|
2754 ↗ | (On Diff #130674) | 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. |