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

miscompile of vanilla integer code by InstCombine #89516

Closed
regehr opened this issue Apr 20, 2024 · 0 comments · Fixed by #89539
Closed

miscompile of vanilla integer code by InstCombine #89516

regehr opened this issue Apr 20, 2024 · 0 comments · Fixed by #89539

Comments

@regehr
Copy link
Contributor

regehr commented Apr 20, 2024

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

this function:

define i8 @f(i8 %0, i8 %1) {
  %3 = icmp slt i8 %1, 0
  %4 = shl i8 1, %0
  %5 = srem i8 1, %4
  %6 = add i8 %5, %4
  %7 = select i1 %3, i8 %6, i8 %5
  ret i8 %7
}

is getting mis-optimized to:

define i8 @f(i8 %0, i8 %1) {
  %3 = icmp ne i8 %0, 0
  %4 = zext i1 %3 to i8
  ret i8 %4
}

here I'll just give Alive's work:

Example:
i8 %#0 = #x00 (0)
i8 %#1 = #xff (255, -1)

Source:
i1 %#3 = #x1 (1)
i8 %#4 = #x01 (1)
i8 %#5 = #x00 (0)
i8 %#6 = #x01 (1)
i8 %#7 = #x01 (1)

Target:
i1 %#3 = #x0 (0)
i8 %#4 = #x00 (0)
Source value: #x01 (1)
Target value: #x00 (0)

cc @nunoplopes @Hatsunespica

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

Successfully merging a pull request may close this issue.

2 participants