[DAGCombiner] Add use check for VSCALE in visitSUB.
authorwanglian <Lian.Wang@streamcomputing.com>
Thu, 18 Aug 2022 09:50:44 +0000 (17:50 +0800)
committerwanglian <Lian.Wang@streamcomputing.com>
Fri, 19 Aug 2022 01:46:18 +0000 (09:46 +0800)
Reviewed By: david-arm

Differential Revision: https://reviews.llvm.org/D132115

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/sve-vscale-combine.ll

index 56beea3..11fb6fe 100644 (file)
@@ -3720,7 +3720,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
   }
 
   // canonicalize (sub X, (vscale * C)) to (add X, (vscale * -C))
-  if (N1.getOpcode() == ISD::VSCALE) {
+  if (N1.getOpcode() == ISD::VSCALE && N1.hasOneUse()) {
     const APInt &IntVal = N1.getConstantOperandAPInt(0);
     return DAG.getNode(ISD::ADD, DL, VT, N0, DAG.getVScale(DL, VT, -IntVal));
   }
index 1ebe91f..9306c20 100644 (file)
@@ -76,10 +76,8 @@ define i32 @combine_sub_vscale_i32(i32 %in) nounwind {
 define i64 @multiple_uses_sub_vscale_i64(i64 %x, i64 %y) nounwind {
 ; CHECK-LABEL: multiple_uses_sub_vscale_i64:
 ; CHECK-NEXT:  rdvl    x8, #1
-; CHECK-NEXT:  rdvl    x9, #-1
 ; CHECK-NEXT:  lsr     x8, x8, #4
-; CHECK-NEXT:  asr     x9, x9, #4
-; CHECK-NEXT:  add     x9, x0, x9
+; CHECK-NEXT:  sub     x9, x0, x8
 ; CHECK-NEXT:  add     x8, x1, x8
 ; CHECK-NEXT:  mul     x0, x9, x8
 ; CHECK-NEXT:  ret