[llvm] 7f518ee - [DAG] Add a one-use check to concat -> scalar_to_vector fold. (#79510)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 10:17:22 PST 2024


Author: David Green
Date: 2024-01-26T18:17:17Z
New Revision: 7f518ee9eaa53fcd475e374aaed05ada4573d115

URL: https://github.com/llvm/llvm-project/commit/7f518ee9eaa53fcd475e374aaed05ada4573d115
DIFF: https://github.com/llvm/llvm-project/commit/7f518ee9eaa53fcd475e374aaed05ada4573d115.diff

LOG: [DAG] Add a one-use check to concat -> scalar_to_vector fold. (#79510)

Without this we can end up with multiple copies from gpr->fpr.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/test/CodeGen/AArch64/pr79100.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 2947ca7532b80de..87184fe409eade6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -23842,7 +23842,7 @@ SDValue DAGCombiner::visitCONCAT_VECTORS(SDNode *N) {
     }
 
     // concat_vectors(scalar, undef) -> scalar_to_vector(scalar)
-    if (!Scalar.getValueType().isVector()) {
+    if (!Scalar.getValueType().isVector() && In.hasOneUse()) {
       // If the bitcast type isn't legal, it might be a trunc of a legal type;
       // look through the trunc so we can still do the transform:
       //   concat_vectors(trunc(scalar), undef) -> scalar_to_vector(scalar)

diff  --git a/llvm/test/CodeGen/AArch64/pr79100.ll b/llvm/test/CodeGen/AArch64/pr79100.ll
index 8e8cd7ed53b63e1..a6e002a5c3d7f3a 100644
--- a/llvm/test/CodeGen/AArch64/pr79100.ll
+++ b/llvm/test/CodeGen/AArch64/pr79100.ll
@@ -1,26 +1,16 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s -mtriple=aarch64 | FileCheck %s --check-prefixes=CHECK,CHECK-SD
-; RUN: llc < %s -mtriple=aarch64 -global-isel 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-GI
+; RUN: llc < %s -mtriple=aarch64 | FileCheck %s --check-prefixes=CHECK
+; RUN: llc < %s -mtriple=aarch64 -global-isel 2>&1 | FileCheck %s --check-prefixes=CHECK
 
 define <16 x i8> @test_2(i64 %0) {
-; CHECK-SD-LABEL: test_2:
-; CHECK-SD:       // %bb.0: // %Entry
-; CHECK-SD-NEXT:    fmov d1, x0
-; CHECK-SD-NEXT:    fmov d2, x0
-; CHECK-SD-NEXT:    movi v0.16b, #15
-; CHECK-SD-NEXT:    ushr v1.8b, v1.8b, #4
-; CHECK-SD-NEXT:    zip1 v1.16b, v2.16b, v1.16b
-; CHECK-SD-NEXT:    and v0.16b, v1.16b, v0.16b
-; CHECK-SD-NEXT:    ret
-;
-; CHECK-GI-LABEL: test_2:
-; CHECK-GI:       // %bb.0: // %Entry
-; CHECK-GI-NEXT:    fmov d1, x0
-; CHECK-GI-NEXT:    movi v0.16b, #15
-; CHECK-GI-NEXT:    ushr v2.8b, v1.8b, #4
-; CHECK-GI-NEXT:    zip1 v1.16b, v1.16b, v2.16b
-; CHECK-GI-NEXT:    and v0.16b, v1.16b, v0.16b
-; CHECK-GI-NEXT:    ret
+; CHECK-LABEL: test_2:
+; CHECK:       // %bb.0: // %Entry
+; CHECK-NEXT:    fmov d1, x0
+; CHECK-NEXT:    movi v0.16b, #15
+; CHECK-NEXT:    ushr v2.8b, v1.8b, #4
+; CHECK-NEXT:    zip1 v1.16b, v1.16b, v2.16b
+; CHECK-NEXT:    and v0.16b, v1.16b, v0.16b
+; CHECK-NEXT:    ret
 Entry:
   %1 = bitcast i64 %0 to <8 x i8>
   %2 = lshr <8 x i8> %1, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>


        


More information about the llvm-commits mailing list