[PATCH] D106850: [InstCombine] Simplify llvm.vscale when vscale_range attribute exists
JunMa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 26 23:17:26 PDT 2021
junparser created this revision.
junparser added reviewers: efriedma, sdesmalen, david-arm, spatel, craig.topper, frasercrmck.
Herald added a subscriber: hiraditya.
junparser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Reduce llvm.vscale to constant based on vscale_range attribute.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106850
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/fold-vscale.ll
Index: llvm/test/Transforms/InstCombine/fold-vscale.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/fold-vscale.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i64 @vscale_i64() #1 {
+; CHECK-LABEL: @vscale_i64(
+; CHECK-NEXT: ret i64 16
+;
+ %1 = call i64 @llvm.vscale.i64()
+ %out = shl i64 %1, 4
+ ret i64 %out
+}
+
+define i32 @vscale_i32() #2 {
+; CHECK-LABEL: @vscale_i32(
+; CHECK-NEXT: ret i32 8
+;
+ %1 = call i32 @llvm.vscale.i32()
+ %out = shl i32 %1, 2
+ ret i32 %out
+}
+
+define i64 @vscale_i64_diff() #3 {
+; CHECK-LABEL: @vscale_i64_diff(
+; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[OUT:%.*]] = shl i64 [[TMP1]], 4
+; CHECK-NEXT: ret i64 [[OUT]]
+;
+ %1 = call i64 @llvm.vscale.i64()
+ %out = shl i64 %1, 4
+ ret i64 %out
+}
+
+; Function Attrs: nofree nosync nounwind readnone willreturn
+declare i64 @llvm.vscale.i64() #0
+
+; Function Attrs: nofree nosync nounwind readnone willreturn
+declare i32 @llvm.vscale.i32() #0
+
+attributes #0 = { nofree nosync nounwind readnone willreturn }
+attributes #1 = { mustprogress nofree nosync nounwind uwtable vscale_range(1,1) }
+attributes #2 = { mustprogress nofree nosync nounwind uwtable vscale_range(2,2) }
+attributes #3 = { mustprogress nofree nosync nounwind uwtable vscale_range(2,4) }
+
+
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2056,6 +2056,17 @@
}
break;
}
+ case Intrinsic::vscale: {
+ auto Attr = II->getFunction()->getFnAttribute(Attribute::VScaleRange);
+ if (!Attr.isValid())
+ break;
+ unsigned MinSVEVectorSize, MaxSVEVectorSize;
+ std::tie(MinSVEVectorSize, MaxSVEVectorSize) = Attr.getVScaleRangeArgs();
+ if (MinSVEVectorSize == MaxSVEVectorSize && MaxSVEVectorSize != 0)
+ return replaceInstUsesWith(
+ CI, ConstantInt::get(II->getType(), MinSVEVectorSize));
+ break;
+ }
default: {
// Handle target specific intrinsics
Optional<Instruction *> V = targetInstCombineIntrinsic(*II);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106850.361914.patch
Type: text/x-patch
Size: 2368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210727/4d7d8e43/attachment.bin>
More information about the llvm-commits
mailing list