-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LV] Strip redundant casts (NFC) #128177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LV] Strip redundant casts (NFC) #128177
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/128177.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index e8a5db28ea0a4..ffccfbf30e46a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1243,8 +1243,8 @@ class LoopVectorizationCostModel {
return false;
// Get the source and destination types of the truncate.
- Type *SrcTy = toVectorTy(cast<CastInst>(I)->getSrcTy(), VF);
- Type *DestTy = toVectorTy(cast<CastInst>(I)->getDestTy(), VF);
+ Type *SrcTy = toVectorTy(Trunc->getSrcTy(), VF);
+ Type *DestTy = toVectorTy(Trunc->getDestTy(), VF);
// If the truncate is free for the given types, return false. Replacing a
// free truncate with an induction variable would add an induction variable
@@ -5132,7 +5132,7 @@ LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF,
return 1;
}
- unsigned F = static_cast<unsigned>(MaxNestedScalarReductionIC);
+ unsigned F = MaxNestedScalarReductionIC;
SmallIC = std::min(SmallIC, F);
StoresIC = std::min(StoresIC, F);
LoadsIC = std::min(LoadsIC, F);
@@ -10303,8 +10303,7 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) {
EpiWidenedPhis.insert(
cast<PHINode>(R.getVPSingleValue()->getUnderlyingValue()));
}
- for (VPRecipeBase &R : make_early_inc_range(
- *cast<VPIRBasicBlock>(MainPlan.getScalarHeader()))) {
+ for (VPRecipeBase &R : make_early_inc_range(*MainPlan.getScalarHeader())) {
auto *VPIRInst = cast<VPIRInstruction>(&R);
auto *IRI = dyn_cast<PHINode>(&VPIRInst->getInstruction());
if (!IRI)
|
@llvm/pr-subscribers-vectorizers Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/128177.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index e8a5db28ea0a4..ffccfbf30e46a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1243,8 +1243,8 @@ class LoopVectorizationCostModel {
return false;
// Get the source and destination types of the truncate.
- Type *SrcTy = toVectorTy(cast<CastInst>(I)->getSrcTy(), VF);
- Type *DestTy = toVectorTy(cast<CastInst>(I)->getDestTy(), VF);
+ Type *SrcTy = toVectorTy(Trunc->getSrcTy(), VF);
+ Type *DestTy = toVectorTy(Trunc->getDestTy(), VF);
// If the truncate is free for the given types, return false. Replacing a
// free truncate with an induction variable would add an induction variable
@@ -5132,7 +5132,7 @@ LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF,
return 1;
}
- unsigned F = static_cast<unsigned>(MaxNestedScalarReductionIC);
+ unsigned F = MaxNestedScalarReductionIC;
SmallIC = std::min(SmallIC, F);
StoresIC = std::min(StoresIC, F);
LoadsIC = std::min(LoadsIC, F);
@@ -10303,8 +10303,7 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) {
EpiWidenedPhis.insert(
cast<PHINode>(R.getVPSingleValue()->getUnderlyingValue()));
}
- for (VPRecipeBase &R : make_early_inc_range(
- *cast<VPIRBasicBlock>(MainPlan.getScalarHeader()))) {
+ for (VPRecipeBase &R : make_early_inc_range(*MainPlan.getScalarHeader())) {
auto *VPIRInst = cast<VPIRInstruction>(&R);
auto *IRI = dyn_cast<PHINode>(&VPIRInst->getInstruction());
if (!IRI)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the tidy-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning this up! It would be great if there was an automatic way to catch such redundant casts. I originally thought that maybe cast
could have a static_assert
to check if the source and destination types are the same, but I think there are a number of cases where they are redundant due to being used in some other templates :(
No description provided.