Skip to content

InstructionSimplification: simplify negated integer comparisons #82804

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eeckstein
Copy link
Contributor

Replaces a builtin "xor", which negates its operand comparison

  %3 = builtin "cmp_slt_Int64"(%1, %2) : $Builtin.Int1
  %4 = integer_literal $Builtin.Int1, -1
  %5 = builtin "xor_Int1"(%3, %4) : $Builtin.Int1

with the negated comparison

  %5 = builtin "cmp_ge_Int64"(%1, %2) : $Builtin.Int1

This makes LLVM's IPSCCP happy.

rdar://154950810

@eeckstein eeckstein changed the title InstructionSimplification: simplify negated integer comparsions InstructionSimplification: simplify negated integer comparisons Jul 4, 2025
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

Copy link
Contributor

@nate-chandler nate-chandler left a comment

Choose a reason for hiding this comment

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

LGTM

Replaces a builtin "xor", which negates its operand comparison
```
  %3 = builtin "cmp_slt_Int64"(%1, %2) : $Builtin.Int1
  %4 = integer_literal $Builtin.Int1, -1
  %5 = builtin "xor_Int1"(%3, %4) : $Builtin.Int1
```
with the negated comparison
```
  %5 = builtin "cmp_ge_Int64"(%1, %2) : $Builtin.Int1
```

This makes LLVM's IPSCCP happy.

rdar://154950810
@eeckstein eeckstein force-pushed the simplify_negated_comparisons branch from d7e4213 to a33cfae Compare July 4, 2025 18:51
@eeckstein eeckstein marked this pull request as draft July 4, 2025 18:52
Copy link
Contributor

@meg-gupta meg-gupta left a comment

Choose a reason for hiding this comment

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

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants