-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] Use cast instead of dyn_cast for Src and Dst vec types in VecCombine folding #134432
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
Conversation
SrcVecTy and DstVecTy are used without a null check, and originate from a dyn_cast. This patch adds an assertion that these values are non-null before they are used/dereferenced.
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-vectorizers Author: None (calebwat) ChangesSrcVecTy and DstVecTy are used without a null check, and originate from a dyn_cast. This patch adds an assertion that these values are non-null before they are used/dereferenced. Full diff: https://github.com/llvm/llvm-project/pull/134432.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 4bfe41a5ed00d..fc04266cac51b 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -2052,6 +2052,9 @@ bool VectorCombine::foldShuffleOfSelects(Instruction &I) {
auto *SrcVecTy = dyn_cast<FixedVectorType>(T1->getType());
auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType());
+ assert(SrcVecTy && DstVecTy &&
+ "Expected shuffle/select vector types to be defined");
+
auto SK = TargetTransformInfo::SK_PermuteTwoSrc;
auto SelOp = Instruction::Select;
InstructionCost OldCost = TTI.getCmpSelInstrCost(
|
@@ -2052,6 +2052,9 @@ bool VectorCombine::foldShuffleOfSelects(Instruction &I) { | |||
|
|||
auto *SrcVecTy = dyn_cast<FixedVectorType>(T1->getType()); | |||
auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType()); | |||
assert(SrcVecTy && DstVecTy && |
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.
If they don't expect to be nullptr
, a cast
would be more appropriate.
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.
yes - replace those 2 dyn_cast with cast - the previous dyn_cast checks for the select condition operands should be ensuring FixedVectorType for everything
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.
Good points, thank you! I've updated the PR accordingly.
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 - cheers
…mbine folding (llvm#134432) SrcVecTy and DstVecTy are used without a null check, and originate from a dyn_cast. This patch adjusts this to use a fixed cast, since it is not checked for null before use otherwise, but is semantically guaranteed from previous checks.
SrcVecTy and DstVecTy are used without a null check, and originate from a dyn_cast. This patch adjusts this to use a fixed cast, since it is not checked for null before use otherwise, but is semantically guaranteed from previous checks.