[InstCombine] Replace undef with poison in a test#199757
Conversation
|
Hello @xarkenz 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
@llvm/pr-subscribers-llvm-transforms Author: Sean Clarke (xarkenz) ChangesThis is intended as part of the effort to deprecate undef. PoisonValue inherits from UndefValue, so testing with poison in this case should imply that it works with undef as well. Checks were regenerated using UTC. Full diff: https://github.com/llvm/llvm-project/pull/199757.diff 1 Files Affected:
diff --git a/llvm/test/Transforms/InstCombine/sub-xor.ll b/llvm/test/Transforms/InstCombine/sub-xor.ll
index 48e6d830c41f6..b3c35d90e64b3 100644
--- a/llvm/test/Transforms/InstCombine/sub-xor.ll
+++ b/llvm/test/Transforms/InstCombine/sub-xor.ll
@@ -145,15 +145,15 @@ define <2 x i8> @xor_add_splat(<2 x i8> %x) {
ret <2 x i8> %add
}
-define <2 x i8> @xor_add_splat_undef(<2 x i8> %x) {
-; CHECK-LABEL: @xor_add_splat_undef(
+define <2 x i8> @xor_add_splat_poison(<2 x i8> %x) {
+; CHECK-LABEL: @xor_add_splat_poison(
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], splat (i8 24)
-; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[AND]], <i8 63, i8 undef>
-; CHECK-NEXT: [[ADD:%.*]] = add <2 x i8> [[XOR]], splat (i8 42)
+; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[AND]], <i8 63, i8 poison>
+; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw <2 x i8> [[XOR]], splat (i8 42)
; CHECK-NEXT: ret <2 x i8> [[ADD]]
;
%and = and <2 x i8> %x, <i8 24, i8 24>
- %xor = xor <2 x i8> %and, <i8 63, i8 undef>
+ %xor = xor <2 x i8> %and, <i8 63, i8 poison>
%add = add <2 x i8> %xor, <i8 42, i8 42>
ret <2 x i8> %add
}
|
artagnon
left a comment
There was a problem hiding this comment.
Found the code responsible for adding wrap-flags in InstCombineAddSub's visitAdd:
bool Changed = false;
if (!I.hasNoSignedWrap() && willNotOverflowSignedAdd(LHSCache, RHSCache, I)) {
Changed = true;
I.setHasNoSignedWrap(true);
}
if (!I.hasNoUnsignedWrap() &&
willNotOverflowUnsignedAdd(LHSCache, RHSCache, I)) {
Changed = true;
I.setHasNoUnsignedWrap(true);
}I think willNotOverflowSignedAdd is doing the right thing on poison, and falls over on undef.
|
@xarkenz Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
This is intended as part of the effort to deprecate undef. The additional wrap-flags are due to the fact that the add can no longer overflow with poison, but could overflow with undef.
Alive2 proof: https://alive2.llvm.org/ce/z/qiRYcQ