AArch64: Do not create CCMP on multiple users.
authorMatthias Braun <matze@braunis.de>
Thu, 20 Aug 2015 23:33:31 +0000 (23:33 +0000)
committerMatthias Braun <matze@braunis.de>
Thu, 20 Aug 2015 23:33:31 +0000 (23:33 +0000)
Create CMP;CCMP sequences from and/or trees does not gain us anything if
the and/or tree is materialized to a GP register anyway. While most of
the code already checked for hasOneUse() there was one important case
missing.

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

lib/Target/AArch64/AArch64ISelLowering.cpp
test/CodeGen/AArch64/arm64-ccmp.ll

index 206088dd5e8aea781562f50ef544a1f6770e45d3..3d1235bac0a00ab86c3fb489a8074c8194b92d8b 100644 (file)
@@ -1349,7 +1349,7 @@ static SDValue emitConjunctionDisjunctionTree(SelectionDAG &DAG, SDValue Val,
     unsigned NZCV = AArch64CC::getNZCVToSatisfyCondCode(InvOutCC);
     return emitConditionalComparison(LHS, RHS, CC, CCOp, ConditionOp, NZCV, DL,
                                      DAG);
-  } else if (Opcode != ISD::AND && Opcode != ISD::OR)
+  } else if ((Opcode != ISD::AND && Opcode != ISD::OR) || !Val->hasOneUse())
     return SDValue();
 
   assert((Opcode == ISD::OR || !PushNegate)
index 446e5ce8cc4a43e65f281e729c78e99d676fbbcb..d8ad067a1bfa4e1d1bc3faab4c71e6f11f7cea2c 100644 (file)
@@ -373,8 +373,8 @@ define i32 @select_ororand(i32 %w0, i32 %w1, i32 %w2, i32 %w3) {
   ret i32 %sel
 }
 
-; CHECK-LABEL: select_noccmp
-define i64 @select_noccmp(i64 %v1, i64 %v2, i64 %v3, i64 %r) {
+; CHECK-LABEL: select_noccmp1
+define i64 @select_noccmp1(i64 %v1, i64 %v2, i64 %v3, i64 %r) {
 ; CHECK-NOT: CCMP
   %c0 = icmp slt i64 %v1, 0
   %c1 = icmp sgt i64 %v1, 13
@@ -386,3 +386,19 @@ define i64 @select_noccmp(i64 %v1, i64 %v2, i64 %v3, i64 %r) {
   %sel = select i1 %or, i64 0, i64 %r
   ret i64 %sel
 }
+
+@g = global i32 0
+
+; Should not use ccmp if we have to compute the or expression in an integer
+; register anyway because of other users.
+; CHECK-LABEL: select_noccmp2
+define i64 @select_noccmp2(i64 %v1, i64 %v2, i64 %v3, i64 %r) {
+; CHECK-NOT: CCMP
+  %c0 = icmp slt i64 %v1, 0
+  %c1 = icmp sgt i64 %v1, 13
+  %or = or i1 %c0, %c1
+  %sel = select i1 %or, i64 0, i64 %r
+  %ext = sext i1 %or to i32
+  store volatile i32 %ext, i32* @g
+  ret i64 %sel
+}