[PATCH] D101778: [CPG][ARM] Optimize towards branch on zero in codegenprepare

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 3 12:16:32 PDT 2021


dmgreen created this revision.
dmgreen added reviewers: SjoerdMeijer, ostannard, efriedma, NickGuy, samtebbs.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
dmgreen requested review of this revision.
Herald added a project: LLVM.

This adds a simple fold into codegenprepare that converts comparison of branches towards comparison with zero if possible. For example:

    %c = icmp ult %x, 8
    br %c, bla, blb
    %tc = lshr %x, 3
  becomes
    %tc = lshr %x, 3
    %c = icmp eq %tc, 0
    br %c, bla, blb

As a first order approximation, this can reduce the number of instructions needed to perform the branch as the shift is (often) needed anyway. At the moment this does not effect very much, as llvm tends to prefer the opposite form. But it can protect against regressions from commits like rG9423f78240a2 <https://reviews.llvm.org/rG9423f78240a216e3f38b394a41fe3427dee22c26>.

Simple cases of Add and Sub are added along with Shift, equally as the comparison to zero can often be folded with cpsr flags.


https://reviews.llvm.org/D101778

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/Target/ARM/ARMISelLowering.h
  llvm/test/CodeGen/ARM/branch-on-zero.ll
  llvm/test/CodeGen/Thumb2/2010-02-11-phi-cycle.ll
  llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101778.342494.patch
Type: text/x-patch
Size: 13314 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210503/08490278/attachment.bin>


More information about the llvm-commits mailing list