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] shoudn't set exact on shr (shl ...) for undefined inputs #114352

Open
bongjunj opened this issue Oct 31, 2024 · 0 comments
Open

[InstCombine] shoudn't set exact on shr (shl ...) for undefined inputs #114352

bongjunj opened this issue Oct 31, 2024 · 0 comments

Comments

@bongjunj
Copy link

// shr (shl X, Y), Y
if (match(I.getOperand(0), m_Shl(m_Value(), m_Specific(I.getOperand(1))))) {
I.setIsExact();
return true;
}

Alive2 report: https://alive2.llvm.org/ce/z/q2vHmJ

----------------------------------------
define i32 @t6_twoshifts.2(i32 %x, i8 %shamt) {
bb:
  %#0 = ctpop i8 %shamt
  %shamt_wide = sext i8 %#0 to i32
  br label %work

work:
  %n0 = shl i32 %x, %shamt_wide
  %r = ashr i32 %n0, %shamt_wide
  br label %end

end:
  ret i32 %r
}
=>
define i32 @t6_twoshifts.2(i32 %x, i8 %shamt) {
bb:
  br label %work

work:
  br label %end

end:
  %#0 = ctpop i8 %shamt
  %#range_0_%#0 = !range i8 %#0, i8 0, i8 9
  %shamt_wide = zext nneg i8 %#range_0_%#0 to i32
  %n0 = shl i32 %x, %shamt_wide
  %r = ashr exact i32 %n0, %shamt_wide
  ret i32 %r
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i32 %x = #x00000002 (2)
i8 %shamt = undef

Source:
i8 %#0 = #x00 (0)	[based on undef value]
i32 %shamt_wide = #x00000000 (0)
  >> Jump to %work
i32 %n0 = #x00000002 (2)
i32 %r = #x00000002 (2)	[based on undef value]
  >> Jump to %end

Target:
  >> Jump to %work
  >> Jump to %end
i8 %#0 = #x00 (0)
i8 %#range_0_%#0 = #x00 (0)
i32 %shamt_wide = #x00000000 (0)
i32 %n0 = #x00000002 (2)
i32 %r = poison
Source value: #x00000002 (2)
Target value: poison

Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
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