-
Notifications
You must be signed in to change notification settings - Fork 14.3k
SROA generate a noundef instead of splatting a noundef int #145122
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
The SROA tests can be found here: https://github.com/llvm/llvm-project/tree/main/llvm/test/Transforms/SROA You can either create a new file or try to find an existing one for this code path -- the easiest way to do that is to add an assert and see which tests fail :) It's worth noting that we have another copy of the memset splat generation code here, using a different implementation: llvm-project/llvm/lib/Transforms/Utils/VNCoercion.cpp Lines 415 to 442 in 4373463
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- llvm/lib/Transforms/Scalar/SROA.cpp View the diff from clang-format here.diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 028bcde5a..403baed93 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3222,14 +3222,14 @@ private:
Type *SplatIntTy = Type::getIntNTy(VTy->getContext(), Size * 8);
if (isa<UndefValue>(V)) {
- V = UndefValue::get(VTy);
+ V = UndefValue::get(VTy);
} else {
- V = IRB.CreateMul(
- IRB.CreateZExt(V, SplatIntTy, "zext"),
- IRB.CreateUDiv(Constant::getAllOnesValue(SplatIntTy),
- IRB.CreateZExt(Constant::getAllOnesValue(V->getType()),
- SplatIntTy)),
- "isplat");
+ V = IRB.CreateMul(
+ IRB.CreateZExt(V, SplatIntTy, "zext"),
+ IRB.CreateUDiv(Constant::getAllOnesValue(SplatIntTy),
+ IRB.CreateZExt(Constant::getAllOnesValue(V->getType()),
+ SplatIntTy)),
+ "isplat");
}
return V;
}
|
You can test this locally with the following command:git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 'HEAD~1' HEAD llvm/lib/Transforms/Scalar/SROA.cpp The following files introduce new uses of undef:
Undef is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields In tests, avoid using For example, this is considered a bad practice: define void @fn() {
...
br i1 undef, ...
} Please use the following instead: define void @fn(i1 %cond) {
...
br i1 %cond, ...
} Please refer to the Undefined Behavior Manual for more information. |
Fixes #145121
This is just a fix for the SROA behavior, and I think that will also avoid what EarlyCSE is doing. Which is a bit unfortunate, because I'd like to be well-motivated to fix both passes.
Where should I add a test for this? I think I should add a regression test, but I don't understand how the tests are organized.