[llvm] e914421 - [SLP]Do correct signedness analysis for externally used scalars
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 24 09:02:37 PDT 2024
Author: Alexey Bataev
Date: 2024-10-24T08:59:24-07:00
New Revision: e914421d7fbf22059ea2180233add0c914ec80f0
URL: https://github.com/llvm/llvm-project/commit/e914421d7fbf22059ea2180233add0c914ec80f0
DIFF: https://github.com/llvm/llvm-project/commit/e914421d7fbf22059ea2180233add0c914ec80f0.diff
LOG: [SLP]Do correct signedness analysis for externally used scalars
If the scalars is used externally is in the root node, it may have
incorrect signedness info because of the conflict with the demanded bits
analysis. Need to perform exact signedness analysis and compute it
rather than rely on the precomputed value, which might be incorrect for
alternate zext/sext nodes.
Fixes #113520
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/SystemZ/ext-alt-node-must-ext.ll
llvm/test/Transforms/SLPVectorizer/resized-alt-shuffle-after-minbw.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 012d85353f085e..2afd02dae3a8b8 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -12068,8 +12068,9 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
auto It = MinBWs.find(Entry);
if (It != MinBWs.end()) {
auto *MinTy = IntegerType::get(F->getContext(), It->second.first);
- unsigned Extend =
- It->second.second ? Instruction::SExt : Instruction::ZExt;
+ unsigned Extend = isKnownNonNegative(EU.Scalar, SimplifyQuery(*DL))
+ ? Instruction::ZExt
+ : Instruction::SExt;
VecTy = getWidenedType(MinTy, BundleWidth);
ExtraCost = TTI->getExtractWithExtendCost(Extend, EU.Scalar->getType(),
VecTy, EU.Lane);
@@ -15784,8 +15785,9 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
// to the larger type.
ExV = Ex;
if (Scalar->getType() != Ex->getType())
- ExV = Builder.CreateIntCast(Ex, Scalar->getType(),
- MinBWs.find(E)->second.second);
+ ExV = Builder.CreateIntCast(
+ Ex, Scalar->getType(),
+ !isKnownNonNegative(Scalar, SimplifyQuery(*DL)));
auto *I = dyn_cast<Instruction>(Ex);
ScalarToEEs[Scalar].try_emplace(I ? I->getParent()
: &F->getEntryBlock(),
diff --git a/llvm/test/Transforms/SLPVectorizer/SystemZ/ext-alt-node-must-ext.ll b/llvm/test/Transforms/SLPVectorizer/SystemZ/ext-alt-node-must-ext.ll
index 979d0ea66bac9a..d0c50b4dc3e4df 100644
--- a/llvm/test/Transforms/SLPVectorizer/SystemZ/ext-alt-node-must-ext.ll
+++ b/llvm/test/Transforms/SLPVectorizer/SystemZ/ext-alt-node-must-ext.ll
@@ -17,7 +17,7 @@ define i32 @test(ptr %0, ptr %1) {
; CHECK-NEXT: [[TMP13:%.*]] = extractelement <2 x i8> [[TMP12]], i32 0
; CHECK-NEXT: [[DOTNEG:%.*]] = sext i8 [[TMP13]] to i32
; CHECK-NEXT: [[TMP15:%.*]] = extractelement <2 x i8> [[TMP12]], i32 1
-; CHECK-NEXT: [[TMP8:%.*]] = sext i8 [[TMP15]] to i32
+; CHECK-NEXT: [[TMP8:%.*]] = zext i8 [[TMP15]] to i32
; CHECK-NEXT: [[TMP10:%.*]] = add nsw i32 [[DOTNEG]], [[TMP8]]
; CHECK-NEXT: ret i32 [[TMP10]]
;
diff --git a/llvm/test/Transforms/SLPVectorizer/resized-alt-shuffle-after-minbw.ll b/llvm/test/Transforms/SLPVectorizer/resized-alt-shuffle-after-minbw.ll
index 56281424c7114a..61a84a67c9ff19 100644
--- a/llvm/test/Transforms/SLPVectorizer/resized-alt-shuffle-after-minbw.ll
+++ b/llvm/test/Transforms/SLPVectorizer/resized-alt-shuffle-after-minbw.ll
@@ -80,7 +80,7 @@ define void @func(i32 %0) {
; CHECK-NEXT: [[TMP75:%.*]] = extractelement <32 x i1> [[TMP20]], i32 4
; CHECK-NEXT: [[TMP76:%.*]] = and i1 false, [[TMP75]]
; CHECK-NEXT: [[TMP77:%.*]] = extractelement <32 x i32> [[TMP18]], i32 0
-; CHECK-NEXT: [[TMP78:%.*]] = sext i32 [[TMP77]] to i64
+; CHECK-NEXT: [[TMP78:%.*]] = zext i32 [[TMP77]] to i64
; CHECK-NEXT: [[TMP79:%.*]] = getelementptr float, ptr addrspace(1) null, i64 [[TMP78]]
; CHECK-NEXT: ret void
;
More information about the llvm-commits
mailing list