This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Optimize Branch Comparisons
ClosedPublic

Authored by lenary on Jan 12 2021, 11:22 AM.

Details

Summary

I noticed in D94450 that there were quite a few places where we generate
the sequence:

xN <- comparison ...
xN <- xor xN, 1
bnez xN, symbol

Given we know the XOR will be used by BRCOND, which only looks at the lowest
bit, I think we can remove the XOR and just invert the branch condition in
these cases?

The case mostly seems to come up in floating point tests, where there is often
more logic to combine the results of multiple SETCCs, rather than a single
(BRCOND (SETCC ...) ...).

Diff Detail

Event Timeline

lenary created this revision.Jan 12 2021, 11:22 AM
lenary requested review of this revision.Jan 12 2021, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2021, 11:22 AM
jrtc27 added inline comments.Jan 12 2021, 11:44 AM
llvm/lib/Target/RISCV/RISCVInstrInfo.td
969

Needs to be plural now

972

Hmm, it's a shame not is an alias for (xor $arg, -1).

lenary updated this revision to Diff 316236.Jan 12 2021, 2:11 PM
  • Add comments in line with review feedback.
lenary marked 2 inline comments as done.Jan 12 2021, 2:11 PM
lenary added inline comments.
llvm/lib/Target/RISCV/RISCVInstrInfo.td
972

Yeah, this importantly is boolean not, rather than bitwise not.

This revision is now accepted and ready to land.Jan 14 2021, 1:42 PM
This revision was automatically updated to reflect the committed changes.