[llvm] 4be7fb9 - [SVE] Add folds for truncation of vscale
Dylan Fleming via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 13 02:18:22 PDT 2021
Author: Dylan Fleming
Date: 2021-08-13T10:18:00+01:00
New Revision: 4be7fb9762286e878a2a458711540a865b5df597
URL: https://github.com/llvm/llvm-project/commit/4be7fb9762286e878a2a458711540a865b5df597
DIFF: https://github.com/llvm/llvm-project/commit/4be7fb9762286e878a2a458711540a865b5df597.diff
LOG: [SVE] Add folds for truncation of vscale
Reviewed By: david-arm
Differential Revision: https://reviews.llvm.org/D107453
Added:
llvm/test/Transforms/InstCombine/vscale_trunc.ll
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index ce533f33f65a..86caf6edeff8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -961,6 +961,20 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
return BinaryOperator::CreateAdd(NarrowCtlz, WidthDiff);
}
}
+
+ if (match(Src, m_VScale(DL))) {
+ if (Trunc.getFunction()->hasFnAttribute(Attribute::VScaleRange)) {
+ unsigned MaxVScale = Trunc.getFunction()
+ ->getFnAttribute(Attribute::VScaleRange)
+ .getVScaleRangeArgs()
+ .second;
+ if (MaxVScale > 0 && Log2_32(MaxVScale) < DestWidth) {
+ Value *VScale = Builder.CreateVScale(ConstantInt::get(DestTy, 1));
+ return replaceInstUsesWith(Trunc, VScale);
+ }
+ }
+ }
+
return nullptr;
}
diff --git a/llvm/test/Transforms/InstCombine/vscale_trunc.ll b/llvm/test/Transforms/InstCombine/vscale_trunc.ll
new file mode 100644
index 000000000000..040476ce558c
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/vscale_trunc.ll
@@ -0,0 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i8 @vscale_trunc_i32toi8() vscale_range(0, 255) {
+; CHECK-LABEL: @vscale_trunc_i32toi8(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = call i8 @llvm.vscale.i8()
+; CHECK-NEXT: ret i8 [[TMP0]]
+entry:
+ %0 = call i32 @llvm.vscale.i32()
+ %1 = trunc i32 %0 to i8
+ ret i8 %1
+}
+
+
+define i8 @vscale_trunc_i32toi8_poison() vscale_range(0, 256) {
+; CHECK-LABEL: @vscale_trunc_i32toi8_poison(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[TMP0]] to i8
+; CHECK-NEXT: ret i8 [[TMP1]]
+ entry:
+ %0 = call i32 @llvm.vscale.i32()
+ %1 = trunc i32 %0 to i8
+ ret i8 %1
+}
+
+define i8 @vscale_trunc_i32toi8_noAttr() {
+; CHECK-LABEL: @vscale_trunc_i32toi8_noAttr(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[TMP0]] to i8
+; CHECK-NEXT: ret i8 [[TMP1]]
+ entry:
+ %0 = call i32 @llvm.vscale.i32()
+ %1 = trunc i32 %0 to i8
+ ret i8 %1
+}
+
+declare i32 @llvm.vscale.i32()
More information about the llvm-commits
mailing list