Skip to content

[InstCombine] Missed optimization for (a ^ -1) < -a #71789

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

Closed
vladimirradosavljevic opened this issue Nov 9, 2023 · 2 comments
Closed

[InstCombine] Missed optimization for (a ^ -1) < -a #71789

vladimirradosavljevic opened this issue Nov 9, 2023 · 2 comments

Comments

@vladimirradosavljevic
Copy link
Contributor

vladimirradosavljevic commented Nov 9, 2023

This could be optimized to a simple a != 0.
Missed example and proof.

@vladimirradosavljevic vladimirradosavljevic changed the title [InstCombine] Missed optimization for select (a ^ -1) < -a [InstCombine] Missed optimization for (a ^ -1) < -a Nov 9, 2023
@pinskia
Copy link

pinskia commented Nov 19, 2023

What is interesting is GCC is able to catch this to do optimizing it first to:

  _2 = -a_4(D);
  _7 = .ADD_OVERFLOW (a_4(D), _2);
  _8 = IMAGPART_EXPR <_7>;

That is GCC is able to optimize __builtin_add_overflow(a, -a, &tmp) into (tmp = 0, a != 0).

@XChy
Copy link
Member

XChy commented Dec 22, 2023

LLVM(trunk) folds it now.

@XChy XChy closed this as completed Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants