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

Merged
merged 3 commits into from
Jul 18, 2025

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

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

@eeckstein eeckstein force-pushed the simplify_negated_comparisons branch from a33cfae to d429bad Compare July 17, 2025 13:44
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

@eeckstein eeckstein force-pushed the simplify_negated_comparisons branch from d429bad to b4d7b68 Compare July 17, 2025 15:45
@eeckstein
Copy link
Contributor Author

@swift-ci test

So far, only negated comparisons (via xor) were handled. Now, also handle simplified comparisons
That means: make `BuiltinInst` conform to `SILCombineSimplifiable`, but still also run the legacy builtin simplification in SILCombine
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 b4d7b68 to 5064297 Compare July 18, 2025 05:45
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein
Copy link
Contributor Author

@swift-ci smoke test macos

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test macos

@eeckstein eeckstein marked this pull request as ready for review July 18, 2025 15:08
@eeckstein eeckstein merged commit a779e49 into swiftlang:main Jul 18, 2025
3 checks passed
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