[llvm] 7cc57c0 - [AArch64] Handle vector with two different values with efficient vector mask
Jingu Kang via llvm-commits
llvm-commits at lists.llvm.org
Thu May 11 02:41:34 PDT 2023
Author: Jingu Kang
Date: 2023-05-11T10:26:00+01:00
New Revision: 7cc57c07e36fc6b4d176cebb28a9bbe637772175
URL: https://github.com/llvm/llvm-project/commit/7cc57c07e36fc6b4d176cebb28a9bbe637772175
DIFF: https://github.com/llvm/llvm-project/commit/7cc57c07e36fc6b4d176cebb28a9bbe637772175.diff
LOG: [AArch64] Handle vector with two different values with efficient vector mask
When we lower BUILD_VECTOR to VECTOR_SHUFFL, we could generate efficient vector
mask. For example,
t24: v8i8 = BUILD_VECTOR t25, t25, t25, t25, t26, t26, t26, t26
==>
t27: v8i8 = BUILD_VECTOR t26, t26, t26, t26, t26, t26, t26, t26
t28: v8i8 = BUILD_VECTOR t25, t25, t25, t25, t25, t25, t25, t25
t29: v8i8 = vector_shuffle<0,1,2,3,12,13,14,15> t27, t2
Differential Revision: https://reviews.llvm.org/D150345
Added:
Modified:
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/build-vector-two-dup.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 818fe49d1717e..1aacab3ff6855 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -12654,13 +12654,13 @@ SDValue AArch64TargetLowering::LowerBUILD_VECTOR(SDValue Op,
}
}
- // Let's try to generate two DUPs and VECTOR_SHUFFLE. For example,
+ // Let's try to generate VECTOR_SHUFFLE. For example,
//
// t24: v8i8 = BUILD_VECTOR t25, t25, t25, t25, t26, t26, t26, t26
// ==>
- // t28: v8i8 = AArch64ISD::DUP t25
- // t30: v8i8 = AArch64ISD::DUP t26
- // t31: v8i8 = vector_shuffle<0,0,0,0,8,8,8,8> t28, t30
+ // t27: v8i8 = BUILD_VECTOR t26, t26, t26, t26, t26, t26, t26, t26
+ // t28: v8i8 = BUILD_VECTOR t25, t25, t25, t25, t25, t25, t25, t25
+ // t29: v8i8 = vector_shuffle<0,1,2,3,12,13,14,15> t27, t28
if (NumElts >= 8) {
SmallVector<int, 16> MaskVec;
// Build mask for VECTOR_SHUFLLE.
@@ -12668,17 +12668,17 @@ SDValue AArch64TargetLowering::LowerBUILD_VECTOR(SDValue Op,
for (unsigned i = 0; i < NumElts; ++i) {
SDValue Val = Op.getOperand(i);
if (FirstLaneVal == Val)
- MaskVec.push_back(0);
+ MaskVec.push_back(i);
else
- MaskVec.push_back(NumElts);
+ MaskVec.push_back(i + NumElts);
}
SmallVector<SDValue, 8> Ops1(NumElts, Vals[0]);
SmallVector<SDValue, 8> Ops2(NumElts, Vals[1]);
- SDValue DUP1 = LowerBUILD_VECTOR(DAG.getBuildVector(VT, dl, Ops1), DAG);
- SDValue DUP2 = LowerBUILD_VECTOR(DAG.getBuildVector(VT, dl, Ops2), DAG);
+ SDValue VEC1 = DAG.getBuildVector(VT, dl, Ops1);
+ SDValue VEC2 = DAG.getBuildVector(VT, dl, Ops2);
SDValue VECTOR_SHUFFLE =
- DAG.getVectorShuffle(VT, dl, DUP1, DUP2, MaskVec);
+ DAG.getVectorShuffle(VT, dl, VEC1, VEC2, MaskVec);
return VECTOR_SHUFFLE;
}
}
diff --git a/llvm/test/CodeGen/AArch64/build-vector-two-dup.ll b/llvm/test/CodeGen/AArch64/build-vector-two-dup.ll
index accbdd2459d4e..f7f355a9e101d 100644
--- a/llvm/test/CodeGen/AArch64/build-vector-two-dup.ll
+++ b/llvm/test/CodeGen/AArch64/build-vector-two-dup.ll
@@ -98,12 +98,10 @@ entry:
define <8 x i8> @test6(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) {
; CHECK-LABEL: test6:
; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: ld1r { v0.8b }, [x1]
-; CHECK-NEXT: adrp x8, .LCPI5_0
-; CHECK-NEXT: ld1r { v1.8b }, [x0]
-; CHECK-NEXT: mov v1.d[1], v0.d[0]
-; CHECK-NEXT: ldr d0, [x8, :lo12:.LCPI5_0]
-; CHECK-NEXT: tbl v0.8b, { v1.16b }, v0.8b
+; CHECK-NEXT: ld1r { v1.8b }, [x1]
+; CHECK-NEXT: ld1r { v0.8b }, [x0]
+; CHECK-NEXT: mov v0.s[1], v1.s[1]
+; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0
; CHECK-NEXT: ret
entry:
%0 = load i8, ptr %a, align 1
@@ -119,12 +117,10 @@ entry:
define <8 x i8> @test7(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) {
; CHECK-LABEL: test7:
; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: ld1r { v0.8b }, [x0]
-; CHECK-NEXT: adrp x8, .LCPI6_0
-; CHECK-NEXT: ld1r { v1.8b }, [x1]
-; CHECK-NEXT: mov v1.d[1], v0.d[0]
-; CHECK-NEXT: ldr d0, [x8, :lo12:.LCPI6_0]
-; CHECK-NEXT: tbl v0.8b, { v1.16b }, v0.8b
+; CHECK-NEXT: ld1r { v1.8b }, [x0]
+; CHECK-NEXT: ld1r { v0.8b }, [x1]
+; CHECK-NEXT: mov v0.s[1], v1.s[1]
+; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0
; CHECK-NEXT: ret
entry:
%0 = load i8, ptr %a, align 1
More information about the llvm-commits
mailing list