From f09cdf90c0c74f2d6786ac6413bfa98ef574ac9c Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Tue, 22 Aug 2017 11:02:45 +0000 Subject: [PATCH] [ARM] Avoid creating duplicate ANDs in SelectionDAG When expanding a BRCOND into a BR_CC, do not create an AND 1 if one already exists. Review: D36705 Patch by Joel Galenson git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311447 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 13 +++++++++---- test/CodeGen/ARM/wide-compares.ll | 6 +----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 7e4bc3ccb5d..7a208cb53ae 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -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(Tmp2.getOperand(1)) && + dyn_cast(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()), diff --git a/test/CodeGen/ARM/wide-compares.ll b/test/CodeGen/ARM/wide-compares.ll index 8a3332211cb..08e07ef76ad 100644 --- a/test/CodeGen/ARM/wide-compares.ll +++ b/test/CodeGen/ARM/wide-compares.ll @@ -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() -- 2.40.0