[llvm] c552c6c - [AArch64][GlobalISel] Protect against non-reg operands in matchExtAddvToUdotAddv.

David Green via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 15:57:44 PST 2025


Author: David Green
Date: 2025-02-05T23:57:39Z
New Revision: c552c6c914290f45bf015c4023c42e40a91e253e

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

LOG: [AArch64][GlobalISel] Protect against non-reg operands in matchExtAddvToUdotAddv.

In some situations the first operand to an instruction might not be a register
(for example with intrinsics). We are only interested in extend operations, so
make sure the instruction is one we expect before we attempt to access the
first reg.

Added: 
    llvm/test/CodeGen/AArch64/GlobalISel/combine-addv.mir

Modified: 
    llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
index bbf1883925a6905..76520fe5ce20f55 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
@@ -267,10 +267,12 @@ bool matchExtAddvToUdotAddv(MachineInstr &MI, MachineRegisterInfo &MRI,
     SrcTy = MRI.getType(ExtMI1->getOperand(1).getReg());
     std::get<0>(MatchInfo) = ExtMI1->getOperand(1).getReg();
     std::get<1>(MatchInfo) = ExtMI2->getOperand(1).getReg();
-  } else {
+  } else if (I1Opc == TargetOpcode::G_ZEXT || I1Opc == TargetOpcode::G_SEXT) {
     SrcTy = MRI.getType(I1->getOperand(1).getReg());
     std::get<0>(MatchInfo) = I1->getOperand(1).getReg();
     std::get<1>(MatchInfo) = 0;
+  } else {
+    return false;
   }
 
   if (I1Opc == TargetOpcode::G_ZEXT)

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/combine-addv.mir b/llvm/test/CodeGen/AArch64/GlobalISel/combine-addv.mir
new file mode 100644
index 000000000000000..ae08cd9d5bfefd8
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/combine-addv.mir
@@ -0,0 +1,33 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -run-pass=aarch64-prelegalizer-combiner -mtriple aarch64-unknown-unknown -mattr=+dotprod %s -o - | FileCheck %s
+
+---
+name:            vecreduce_intrinsic
+body:             |
+  bb.0:
+    liveins: $q0, $q1, $q2, $q3, $q4
+    ; CHECK-LABEL: name: vecreduce_intrinsic
+    ; CHECK: liveins: $q0, $q1, $q2, $q3, $q4
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $q0
+    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(<4 x s32>) = COPY $q1
+    ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(<4 x s32>) = COPY $q2
+    ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(<4 x s32>) = COPY $q3
+    ; CHECK-NEXT: [[COPY4:%[0-9]+]]:_(<4 x s32>) = COPY $q4
+    ; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<16 x s32>) = G_CONCAT_VECTORS [[COPY1]](<4 x s32>), [[COPY2]](<4 x s32>), [[COPY3]](<4 x s32>), [[COPY4]](<4 x s32>)
+    ; CHECK-NEXT: [[INT:%[0-9]+]]:_(<4 x s32>) = G_INTRINSIC intrinsic(@llvm.experimental.vector.partial.reduce.add), [[COPY]](<4 x s32>), [[CONCAT_VECTORS]](<16 x s32>)
+    ; CHECK-NEXT: [[VECREDUCE_ADD:%[0-9]+]]:_(s32) = G_VECREDUCE_ADD [[INT]](<4 x s32>)
+    ; CHECK-NEXT: $w0 = COPY [[VECREDUCE_ADD]](s32)
+    ; CHECK-NEXT: RET_ReallyLR implicit $w0
+    %0:_(<4 x s32>) = COPY $q0
+    %2:_(<4 x s32>) = COPY $q1
+    %3:_(<4 x s32>) = COPY $q2
+    %4:_(<4 x s32>) = COPY $q3
+    %5:_(<4 x s32>) = COPY $q4
+    %1:_(<16 x s32>) = G_CONCAT_VECTORS %2:_(<4 x s32>), %3:_(<4 x s32>), %4:_(<4 x s32>), %5:_(<4 x s32>)
+    %6:_(<4 x s32>) = G_INTRINSIC intrinsic(@llvm.experimental.vector.partial.reduce.add), %0:_(<4 x s32>), %1:_(<16 x s32>)
+    %7:_(s32) = G_VECREDUCE_ADD %6:_(<4 x s32>)
+    $w0 = COPY %7:_(s32)
+    RET_ReallyLR implicit $w0
+
+...


        


More information about the llvm-commits mailing list