]> granicus.if.org Git - llvm/commitdiff
[ARM] Avoid creating duplicate ANDs in SelectionDAG
authorRenato Golin <renato.golin@linaro.org>
Tue, 22 Aug 2017 11:02:45 +0000 (11:02 +0000)
committerRenato Golin <renato.golin@linaro.org>
Tue, 22 Aug 2017 11:02:45 +0000 (11:02 +0000)
When expanding a BRCOND into a BR_CC, do not create an AND 1
if one already exists.

Review: D36705

Patch by Joel Galenson <jgalenson@google.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311447 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7e4bc3ccb5d390fe178b45fd25517230ca9d9bef..7a208cb53ae5a255254db114fa77453df811a14f 100644 (file)
@@ -3666,10 +3666,15 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
                          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()),
index 8a3332211cb5ded6517789c9eeb9f9b95d9a04fb..08e07ef76ad7651ccd58c4a777815f025356c2fa 100644 (file)
@@ -36,11 +36,7 @@ entry:
   ; 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()