[llvm] r356040 - [DAG] Move integer setcc %x, %x folding into FoldSetCC

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 04:08:57 PDT 2019


Author: rksimon
Date: Wed Mar 13 04:08:57 2019
New Revision: 356040

URL: http://llvm.org/viewvc/llvm-project?rev=356040&view=rev
Log:
[DAG] Move integer setcc %x, %x folding into FoldSetCC

First step towards PR40800 - I intend to move the float case in a separate future patch.

I had to tweak the (overly reduced) thumb2 test and the x86 widening test change is annoying (no longer rematerializable) but we should address this separately.

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

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
    llvm/trunk/test/CodeGen/AArch64/fast-isel-cmp-vec.ll
    llvm/trunk/test/CodeGen/Thumb2/cross-rc-coalescing-2.ll
    llvm/trunk/test/CodeGen/X86/widen_compare-1.ll

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=356040&r1=356039&r2=356040&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Mar 13 04:08:57 2019
@@ -1974,6 +1974,10 @@ SDValue SelectionDAG::FoldSetCC(EVT VT,
     break;
   }
 
+  // We can always fold X == X for integer setcc's.
+  if (N1 == N2 && OpVT.isInteger())
+    return getBoolConstant(ISD::isTrueWhenEqual(Cond), dl, VT, OpVT);
+
   if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2)) {
     const APInt &C2 = N2C->getAPIntValue();
     if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1)) {

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=356040&r1=356039&r2=356040&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Wed Mar 13 04:08:57 2019
@@ -3004,13 +3004,10 @@ SDValue TargetLowering::SimplifySetCC(EV
   if (N0 == N1) {
     // The sext(setcc()) => setcc() optimization relies on the appropriate
     // constant being emitted.
+    assert(!N0.getValueType().isInteger() &&
+           "Integer types should be handled by FoldSetCC");
 
     bool EqTrue = ISD::isTrueWhenEqual(Cond);
-
-    // We can always fold X == X for integer setcc's.
-    if (N0.getValueType().isInteger())
-      return DAG.getBoolConstant(EqTrue, dl, VT, OpVT);
-
     unsigned UOF = ISD::getUnorderedFlavor(Cond);
     if (UOF == 2) // FP operators that are undefined on NaNs.
       return DAG.getBoolConstant(EqTrue, dl, VT, OpVT);

Modified: llvm/trunk/test/CodeGen/AArch64/fast-isel-cmp-vec.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/fast-isel-cmp-vec.ll?rev=356040&r1=356039&r2=356040&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/fast-isel-cmp-vec.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/fast-isel-cmp-vec.ll Wed Mar 13 04:08:57 2019
@@ -24,10 +24,8 @@ bb2:
 define <2 x i32> @icmp_constfold_v2i32(<2 x i32> %a) {
 ; CHECK-LABEL: icmp_constfold_v2i32:
 ; CHECK:      ; %bb.0:
-; CHECK-NEXT:  movi.2d v[[CMP:[0-9]+]], #0xffffffffffffffff
-; CHECK-NEXT: ; %bb.1:
 ; CHECK-NEXT:  movi.2s [[MASK:v[0-9]+]], #1
-; CHECK-NEXT:  and.8b v0, v[[CMP]], [[MASK]]
+; CHECK-NEXT:  and.8b v0, [[MASK]], [[MASK]]
 ; CHECK-NEXT:  ret
   %1 = icmp eq <2 x i32> %a, %a
   br label %bb2
@@ -56,10 +54,9 @@ bb2:
 define <4 x i32> @icmp_constfold_v4i32(<4 x i32> %a) {
 ; CHECK-LABEL: icmp_constfold_v4i32:
 ; CHECK:      ; %bb.0:
-; CHECK-NEXT:  movi.2d v[[CMP:[0-9]+]], #0xffffffffffffffff
-; CHECK-NEXT: ; %bb.1:
 ; CHECK-NEXT:  movi.4h [[MASK:v[0-9]+]], #1
-; CHECK-NEXT:  and.8b [[ZEXT:v[0-9]+]], v[[CMP]], [[MASK]]
+; CHECK-NEXT: ; %bb.1:
+; CHECK-NEXT:  and.8b [[ZEXT:v[0-9]+]], [[MASK]], [[MASK]]
 ; CHECK-NEXT:  ushll.4s v0, [[ZEXT]], #0
 ; CHECK-NEXT:  ret
   %1 = icmp eq <4 x i32> %a, %a
@@ -87,10 +84,8 @@ bb2:
 define <16 x i8> @icmp_constfold_v16i8(<16 x i8> %a) {
 ; CHECK-LABEL: icmp_constfold_v16i8:
 ; CHECK:      ; %bb.0:
-; CHECK-NEXT:  movi.2d [[CMP:v[0-9]+]], #0xffffffffffffffff
-; CHECK-NEXT: ; %bb.1:
 ; CHECK-NEXT:  movi.16b [[MASK:v[0-9]+]], #1
-; CHECK-NEXT:  and.16b v0, [[CMP]], [[MASK]]
+; CHECK-NEXT:  and.16b v0, [[MASK]], [[MASK]]
 ; CHECK-NEXT:  ret
   %1 = icmp eq <16 x i8> %a, %a
   br label %bb2

Modified: llvm/trunk/test/CodeGen/Thumb2/cross-rc-coalescing-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/cross-rc-coalescing-2.ll?rev=356040&r1=356039&r2=356040&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Thumb2/cross-rc-coalescing-2.ll (original)
+++ llvm/trunk/test/CodeGen/Thumb2/cross-rc-coalescing-2.ll Wed Mar 13 04:08:57 2019
@@ -64,7 +64,7 @@ bb8:
   %32 = fsub float %30, %31                       ; <float> [#uses=1]
   %33 = fsub float %10, %32                       ; <float> [#uses=1]
   store float %33, float* undef, align 4
-  %34 = icmp slt i32 undef, undef                 ; <i1> [#uses=1]
+  %34 = icmp slt i32 %tmp54, %tmp80               ; <i1> [#uses=1]
   br i1 %34, label %bb8, label %bb9
 
 bb9:                                              ; preds = %bb8

Modified: llvm/trunk/test/CodeGen/X86/widen_compare-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/widen_compare-1.ll?rev=356040&r1=356039&r2=356040&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/widen_compare-1.ll (original)
+++ llvm/trunk/test/CodeGen/X86/widen_compare-1.ll Wed Mar 13 04:08:57 2019
@@ -7,12 +7,12 @@
 define <2 x i16> @compare_v2i64_to_v2i16_unary(<2 x i16>* %src) nounwind {
 ; X86-LABEL: compare_v2i64_to_v2i16_unary:
 ; X86:       # %bb.0:
-; X86-NEXT:    pcmpeqd %xmm0, %xmm0
+; X86-NEXT:    movaps {{.*#+}} xmm0 = [65535,0,65535,0]
 ; X86-NEXT:    retl
 ;
 ; X64-LABEL: compare_v2i64_to_v2i16_unary:
 ; X64:       # %bb.0:
-; X64-NEXT:    pcmpeqd %xmm0, %xmm0
+; X64-NEXT:    movaps {{.*#+}} xmm0 = [65535,65535]
 ; X64-NEXT:    retq
   %val = load <2 x i16>, <2 x i16>* %src, align 4
   %cmp = icmp uge <2 x i16> %val, %val




More information about the llvm-commits mailing list