[all-commits] [llvm/llvm-project] dd5c52: [CPG][ARM] Optimize towards branch on zero in code...

David Green via All-commits all-commits at lists.llvm.org
Sun May 16 09:54:30 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: dd5c52029d27125bffaca1d1d442eedeae6481b9
      https://github.com/llvm/llvm-project/commit/dd5c52029d27125bffaca1d1d442eedeae6481b9
  Author: David Green <david.green at arm.com>
  Date:   2021-05-16 (Sun, 16 May 2021)

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

  Log Message:
  -----------
  [CPG][ARM] Optimize towards branch on zero in codegenprepare

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.

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

Differential Revision: https://reviews.llvm.org/D101778




More information about the All-commits mailing list