Skip to content
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

[InstCombine] missed reducing/canonicalizing add overflow patterns #59232

Open
rotateright opened this issue Nov 28, 2022 · 1 comment
Open

Comments

@rotateright
Copy link
Contributor

rotateright commented Nov 28, 2022

Forking this off from the multiplication examples in issue #59217 -
These are all equivalent, but we don't transform them:

define i64 @src(i32 %a, i32 %b) {
  %a8 = zext i32 %a to i64
  %b8 = zext i32 %b to i64
  %m8 = add nuw nsw i64 %b8, %a8
  %hi64 = lshr i64 %m8, 32
  ret i64 %hi64
}

define i64 @tgt(i32 %a, i32 %b) {
  %nota = xor i32 %a, -1
  %ov = icmp ult i32 %nota, %b
  %r = zext i1 %ov to i64
  ret i64 %r
}

declare {i32, i1} @llvm.uadd.with.overflow.i32(i32, i32)

define i64 @tgt2(i32 %a, i32 %b) {
  %s = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
  %ov = extractvalue {i32, i1} %s, 1
  %r = zext i1 %ov to i64
  ret i64 %r
}

https://alive2.llvm.org/ce/z/DX2YCM

@rotateright
Copy link
Contributor Author

There was a patch underway when I filed this:
https://reviews.llvm.org/D138814
...and looks like it came up before:
https://reviews.llvm.org/D107552

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

2 participants