[all-commits] [llvm/llvm-project] 6bbfaf: [CGP] Make ICMP_EQ use CR result of ICMP_S(L|G)T d...

Yi-Hong Lyu via All-commits all-commits at lists.llvm.org
Mon Nov 11 09:29:37 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 6bbfafd03782a4bf9522edeaf4860470946ecfd0
      https://github.com/llvm/llvm-project/commit/6bbfafd03782a4bf9522edeaf4860470946ecfd0
  Author: Yi-Hong Lyu <Yi-Hong.Lyu at ibm.com>
  Date:   2019-11-11 (Mon, 11 Nov 2019)

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

  Log Message:
  -----------
  [CGP] Make ICMP_EQ use CR result of ICMP_S(L|G)T dominators

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:

        sld. 5, 3, 4
        ble 0, .LBB0_2
        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.

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




More information about the All-commits mailing list