[PATCH] D36705: Avoid creating duplicate ANDs in SelectionDAG.

Joel Galenson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 14 12:17:02 PDT 2017


jgalenson created this revision.
Herald added a subscriber: javed.absar.

When expanding a BRCOND into a BR_CC, do not create an AND 1 if one already exists.


https://reviews.llvm.org/D36705

Files:
  lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  test/CodeGen/ARM/wide-compares.ll


Index: test/CodeGen/ARM/wide-compares.ll
===================================================================
--- test/CodeGen/ARM/wide-compares.ll
+++ test/CodeGen/ARM/wide-compares.ll
@@ -36,11 +36,7 @@
   ; CHECK-ARM: sbcs {{[^,]+}}, r1, r3
   ; CHECK-THUMB2: subs {{[^,]+}}, r0, r2
   ; CHECK-THUMB2: sbcs.w {{[^,]+}}, r1, r3
-  ; CHECK-ARM: movwge r12, #1
-  ; CHECK-ARM: cmp r12, #0
-  ; CHECK-THUMB2: movge.w r12, #1
-  ; CHECK-THUMB: cmp.w r12, #0
-  ; CHECK: bne [[BB2:\.[0-9A-Za-z_]+]]
+  ; CHECK: bge [[BB2:\.[0-9A-Za-z_]+]]
   br i1 %cmp, label %bb1, label %bb2
 bb1:
   call void @f()
Index: lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -3666,10 +3666,15 @@
                          Tmp2.getOperand(0), Tmp2.getOperand(1),
                          Node->getOperand(2));
     } else {
-      // We test only the i1 bit.  Skip the AND if UNDEF.
-      Tmp3 = (Tmp2.isUndef()) ? Tmp2 :
-        DAG.getNode(ISD::AND, dl, Tmp2.getValueType(), Tmp2,
-                    DAG.getConstant(1, dl, Tmp2.getValueType()));
+      // We test only the i1 bit.  Skip the AND if UNDEF or another AND.
+      if (Tmp2.isUndef() ||
+          (Tmp2.getOpcode() == ISD::AND &&
+           isa<ConstantSDNode>(Tmp2.getOperand(1)) &&
+           dyn_cast<ConstantSDNode>(Tmp2.getOperand(1))->getZExtValue() == 1))
+        Tmp3 = Tmp2;
+      else
+        Tmp3 = DAG.getNode(ISD::AND, dl, Tmp2.getValueType(), Tmp2,
+                           DAG.getConstant(1, dl, Tmp2.getValueType()));
       Tmp1 = DAG.getNode(ISD::BR_CC, dl, MVT::Other, Tmp1,
                          DAG.getCondCode(ISD::SETNE), Tmp3,
                          DAG.getConstant(0, dl, Tmp3.getValueType()),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36705.111046.patch
Type: text/x-patch
Size: 1834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170814/0bf8aa3d/attachment.bin>


More information about the llvm-commits mailing list