[PATCH] D60506: [PowerPC] Make ICMP_EQ use CR result of ICMP_S(L|G)T dominators

Yi-Hong Lyu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 10 05:05:44 PDT 2019


Yi-Hong.Lyu created this revision.
Yi-Hong.Lyu added reviewers: nemanjai, hfinkel, jsji, echristo, stefanp, lei.
Herald added subscribers: llvm-commits, kbarton, hiraditya.
Herald added a project: LLVM.

For example:

  long long test(long long a, long long b) {
    if (a << b > 0)
      return b;
    if (a << b < 0)
      return a;
    return a*b;
  }

Produces:

  # %bb.0:                                # %entry
          sld. 5, 3, 4
          ble 0, .LBB0_2
  # %bb.1:                                # %return
          mr 3, 4
          blr
  .LBB0_2:                                # %if.end
          cmpldi  5, 0
          li 5, 1
          isel 4, 4, 5, 2
          mulld 3, 4, 3
          blr

But the compare (cmpldi 5, 0) is redundant and can be removed (CR0 already contains the result of that comparison).

The root cause of this is that LLVM converts signed comparisons into equality comparison based on dominance. Equality comparisons are unsigned by default, so we get either a record-form or cmp (without the l for logical) feeding a cmpl. That is the situation we want to avoid here.


https://reviews.llvm.org/D60506

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/test/CodeGen/PowerPC/use-cr-result-of-dom-icmp-st.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60506.194492.patch
Type: text/x-patch
Size: 38696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190410/8e68f79d/attachment.bin>


More information about the llvm-commits mailing list