Skip to content

[InstCombine] Replace undef with poison in a test#199757

Merged
artagnon merged 1 commit into
llvm:mainfrom
xarkenz:test-xor-add-splat-poison
May 29, 2026
Merged

[InstCombine] Replace undef with poison in a test#199757
artagnon merged 1 commit into
llvm:mainfrom
xarkenz:test-xor-add-splat-poison

Conversation

@xarkenz
Copy link
Copy Markdown

@xarkenz xarkenz commented May 26, 2026

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

@github-actions
Copy link
Copy Markdown

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.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

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 questions

How 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 @ followed by their GitHub username.

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,
The LLVM Community

@llvmorg-github-actions llvmorg-github-actions Bot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels May 26, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-llvm-transforms

Author: Sean Clarke (xarkenz)

Changes

This 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:

  • (modified) llvm/test/Transforms/InstCombine/sub-xor.ll (+5-5)
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
 }

Comment thread llvm/test/Transforms/InstCombine/sub-xor.ll
Copy link
Copy Markdown
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PoisonValue inherits from UndefValue, so testing with poison in this case should imply that it works with undef as well.

Ah, but the wrap flags are different, and this is a non-trivial proof? EDIT: I took the liberty to edit your commit message.

@artagnon artagnon changed the title Updated test xor_add_splat_undef to use poison instead [InstCombine] Replace undef with poison in a test May 26, 2026
Copy link
Copy Markdown
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RKSimon RKSimon removed their request for review May 27, 2026 08:19
@artagnon artagnon requested a review from nikic May 29, 2026 14:33
@artagnon artagnon merged commit 99b5ebd into llvm:main May 29, 2026
13 checks passed
@github-actions
Copy link
Copy Markdown

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants