[llvm] r311447 - [ARM] Avoid creating duplicate ANDs in SelectionDAG
Renato Golin via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 22 04:02:45 PDT 2017
Author: rengolin
Date: Tue Aug 22 04:02:45 2017
New Revision: 311447
URL: http://llvm.org/viewvc/llvm-project?rev=311447&view=rev
Log:
[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 <jgalenson at google.com>
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
llvm/trunk/test/CodeGen/ARM/wide-compares.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=311447&r1=311446&r2=311447&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Tue Aug 22 04:02:45 2017
@@ -3666,10 +3666,15 @@ bool SelectionDAGLegalize::ExpandNode(SD
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()),
Modified: llvm/trunk/test/CodeGen/ARM/wide-compares.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/wide-compares.ll?rev=311447&r1=311446&r2=311447&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/wide-compares.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/wide-compares.ll Tue Aug 22 04:02:45 2017
@@ -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()
More information about the llvm-commits
mailing list