[llvm] 7b64765 - [SVE] Fix TypeSize related warnings with IR truncates of scalable vectors
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 01:18:31 PDT 2020
Author: David Sherwood
Date: 2020-08-25T09:17:56+01:00
New Revision: 7b64765cd19a60d6d56106769d06cdff5b660479
URL: https://github.com/llvm/llvm-project/commit/7b64765cd19a60d6d56106769d06cdff5b660479
DIFF: https://github.com/llvm/llvm-project/commit/7b64765cd19a60d6d56106769d06cdff5b660479.diff
LOG: [SVE] Fix TypeSize related warnings with IR truncates of scalable vectors
In getCastInstrCost when the instruction is a truncate we were relying
upon the implicit TypeSize -> uint64_t cast when asking if a given type
has the same size as a legal integer. I've changed the code to only
ask the question if the type is fixed length.
I have also changed InstCombinerImpl::SimplifyDemandedUseBits to bail
out for now if the type is a scalable vector.
I've added the following new tests:
Analysis/CostModel/AArch64/sve-trunc.ll
Transforms/InstCombine/AArch64/sve-trunc.ll
for both of these fixes.
Differential revision: https://reviews.llvm.org/D86432
Added:
llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll
llvm/test/Transforms/InstCombine/AArch64/sve-trunc.ll
Modified:
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index ee1527ff8881..bb70b9787080 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -448,13 +448,15 @@ class TargetTransformInfoImplBase {
// Identity and pointer-to-pointer casts are free.
return 0;
break;
- case Instruction::Trunc:
+ case Instruction::Trunc: {
// trunc to a native type is free (assuming the target has compare and
// shift-right of the same width).
- if (DL.isLegalInteger(DL.getTypeSizeInBits(Dst)))
+ TypeSize DstSize = DL.getTypeSizeInBits(Dst);
+ if (!DstSize.isScalable() && DL.isLegalInteger(DstSize.getFixedSize()))
return 0;
break;
}
+ }
return 1;
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index ba9631a83a6f..992fe5edd3ff 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -130,6 +130,9 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
if (Depth == MaxAnalysisRecursionDepth)
return nullptr;
+ if (isa<ScalableVectorType>(VTy))
+ return nullptr;
+
Instruction *I = dyn_cast<Instruction>(V);
if (!I) {
computeKnownBits(V, Known, Depth, CxtI);
diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll b/llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll
new file mode 100644
index 000000000000..32e760f2015d
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll
@@ -0,0 +1,14 @@
+; RUN: opt -mtriple=aarch64-linux-gnu -mattr=+sve -cost-model -analyze < %s 2>%t | FileCheck %s
+; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t
+
+; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it.
+; WARN-NOT: warning
+
+; CHECK: Found an estimated cost of 0 for instruction: %0 = trunc <vscale x 2 x i64> %v to <vscale x 2 x i32>
+
+define void @trunc_nxv2i64_to_nxv2i32(<vscale x 2 x i32>* %ptr, <vscale x 2 x i64> %v) {
+entry:
+ %0 = trunc <vscale x 2 x i64> %v to <vscale x 2 x i32>
+ store <vscale x 2 x i32> %0, <vscale x 2 x i32>* %ptr
+ ret void
+}
diff --git a/llvm/test/Transforms/InstCombine/AArch64/sve-trunc.ll b/llvm/test/Transforms/InstCombine/AArch64/sve-trunc.ll
new file mode 100644
index 000000000000..d18beb5dbdf4
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/AArch64/sve-trunc.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple aarch64-linux-gnu -mattr=+sve -instcombine -S < %s 2>%t | FileCheck %s
+; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t
+
+; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it.
+; WARN-NOT: warning
+
+define void @trunc_nxv2i64_to_nxv2i32(i32* %ptr, <vscale x 4 x i32> %v) {
+; CHECK-LABEL: @trunc_nxv2i64_to_nxv2i32(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i1> @llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
+; CHECK-NEXT: [[TMP1:%.*]] = bitcast <vscale x 4 x i32> [[V:%.*]] to <vscale x 2 x i64>
+; CHECK-NEXT: [[TMP2:%.*]] = call <vscale x 2 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv2i1(<vscale x 16 x i1> [[TMP0]])
+; CHECK-NEXT: [[TMP3:%.*]] = trunc <vscale x 2 x i64> [[TMP1]] to <vscale x 2 x i32>
+; CHECK-NEXT: call void @llvm.aarch64.sve.st1.nxv2i32(<vscale x 2 x i32> [[TMP3]], <vscale x 2 x i1> [[TMP2]], i32* [[PTR:%.*]])
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = call <vscale x 16 x i1> @llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
+ %1 = bitcast <vscale x 4 x i32> %v to <vscale x 2 x i64>
+ %2 = call <vscale x 2 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv2i1(<vscale x 16 x i1> %0)
+ %3 = trunc <vscale x 2 x i64> %1 to <vscale x 2 x i32>
+ call void @llvm.aarch64.sve.st1.nxv2i32(<vscale x 2 x i32> %3, <vscale x 2 x i1> %2, i32* %ptr)
+ ret void
+}
+
+declare void @llvm.aarch64.sve.st1.nxv2i32(<vscale x 2 x i32>, <vscale x 2 x i1>, i32*)
+declare <vscale x 2 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv2i1(<vscale x 16 x i1>)
+declare <vscale x 16 x i1> @llvm.aarch64.sve.ptrue.nxv16i1(i32 %pattern)
More information about the llvm-commits
mailing list