[llvm] 1f2c37a - [AArch64][SVE] Implement isVScaleKnownToBeAPowerOfTwo
David Green via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 07:49:34 PST 2023
Author: David Green
Date: 2023-01-17T15:49:29Z
New Revision: 1f2c37afbe69d048bc518363454ae073f588066e
URL: https://github.com/llvm/llvm-project/commit/1f2c37afbe69d048bc518363454ae073f588066e
DIFF: https://github.com/llvm/llvm-project/commit/1f2c37afbe69d048bc518363454ae073f588066e.diff
LOG: [AArch64][SVE] Implement isVScaleKnownToBeAPowerOfTwo
According to https://developer.arm.com/documentation/102105/ia-00/?lang=en
> Arm is making a retrospective change to the SVE architecture to remove
> the capability of selecting a non-power-of-two vector length in
> non-Streaming SVE as well as in Streaming SVE mode. Specific updates as
> a result of this change will be communicated in due course.
This patch implements the isVScaleKnownToBeAPowerOfTwo method to teach
DAG Combines that VScale will be known to be a power of 2, which helps
reduce or simplify some expressions (notably the udiv in vector trip
count expressions).
Differential Revision: https://reviews.llvm.org/D141486
Added:
Modified:
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/test/CodeGen/AArch64/vscale-power-of-two.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 511c103b53da..78342777c47a 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -6083,6 +6083,10 @@ bool AArch64TargetLowering::mergeStoresAfterLegalization(EVT VT) const {
return !Subtarget->useSVEForFixedLengthVectors();
}
+bool AArch64TargetLowering::isVScaleKnownToBeAPowerOfTwo() const {
+ return true;
+}
+
bool AArch64TargetLowering::useSVEForFixedLengthVectorVT(
EVT VT, bool OverrideNEON) const {
if (!VT.isFixedLengthVector() || !VT.isSimple())
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.h b/llvm/lib/Target/AArch64/AArch64ISelLowering.h
index febb1161b370..3731c5ae2408 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -907,6 +907,8 @@ class AArch64TargetLowering : public TargetLowering {
SDValue Chain, SDValue InFlag,
SDValue PStateSM, bool Entry) const;
+ bool isVScaleKnownToBeAPowerOfTwo() const override;
+
// Normally SVE is only used for byte size vectors that do not fit within a
// NEON vector. This changes when OverrideNEON is true, allowing SVE to be
// used for 64bit and 128bit vectors as well.
diff --git a/llvm/test/CodeGen/AArch64/vscale-power-of-two.ll b/llvm/test/CodeGen/AArch64/vscale-power-of-two.ll
index 0d58f98f477b..201292378221 100644
--- a/llvm/test/CodeGen/AArch64/vscale-power-of-two.ll
+++ b/llvm/test/CodeGen/AArch64/vscale-power-of-two.ll
@@ -7,8 +7,8 @@ define i64 @vscale_lshr(i64 %TC) {
; CHECK-NEXT: rdvl x8, #1
; CHECK-NEXT: lsr x8, x8, #4
; CHECK-NEXT: lsr x8, x8, #3
-; CHECK-NEXT: udiv x9, x0, x8
-; CHECK-NEXT: msub x0, x9, x8, x0
+; CHECK-NEXT: sub x8, x8, #1
+; CHECK-NEXT: and x0, x0, x8
; CHECK-NEXT: ret
%vscale = call i64 @llvm.vscale.i64()
%shifted = lshr i64 %vscale, 3
@@ -21,8 +21,8 @@ define i64 @vscale(i64 %TC) {
; CHECK: // %bb.0:
; CHECK-NEXT: rdvl x8, #1
; CHECK-NEXT: lsr x8, x8, #4
-; CHECK-NEXT: udiv x9, x0, x8
-; CHECK-NEXT: msub x0, x9, x8, x0
+; CHECK-NEXT: sub x8, x8, #1
+; CHECK-NEXT: and x0, x0, x8
; CHECK-NEXT: ret
%vscale = call i64 @llvm.vscale.i64()
%urem = urem i64 %TC, %vscale
@@ -33,8 +33,8 @@ define i64 @vscale_shl(i64 %TC) {
; CHECK-LABEL: vscale_shl:
; CHECK: // %bb.0:
; CHECK-NEXT: cnth x8
-; CHECK-NEXT: udiv x9, x0, x8
-; CHECK-NEXT: msub x0, x9, x8, x0
+; CHECK-NEXT: sub x8, x8, #1
+; CHECK-NEXT: and x0, x0, x8
; CHECK-NEXT: ret
%vscale = call i64 @llvm.vscale.i64()
%shifted = shl i64 %vscale, 3
More information about the llvm-commits
mailing list