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] wrong folding of an extension and a binary operator for undefined inputs #114358

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

Comments

@bongjunj
Copy link

// bo (ext X), (ext Y) --> ext (bo X, Y)
// bo (ext X), C --> ext (bo X, C')
Value *NarrowBO = Builder.CreateBinOp(BO.getOpcode(), X, Y, "narrow");
if (auto *NewBinOp = dyn_cast<BinaryOperator>(NarrowBO)) {
if (IsSext)
NewBinOp->setHasNoSignedWrap();
else
NewBinOp->setHasNoUnsignedWrap();
}
return CastInst::Create(CastOpc, NarrowBO, BO.getType());
}

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

----------------------------------------
define i32 @test8_vec.3(i16 %V) {
#0:
  %ashr = ashr i16 %V, 8
  %sext = sext i16 %ashr to i32
  %#1 = sext i16 %ashr to i32
  %mul = mul i32 %sext, %#1
  ret i32 %mul
}
=>
define i32 @test8_vec.3(i16 %V) {
#0:
  %ashr = ashr i16 %V, 8
  %narrow = mul nsw i16 %ashr, %ashr
  %mul = zext nneg i16 %narrow to i32
  ret i32 %mul
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i16 %V = undef

Source:
i16 %ashr = #x0000 (0)	[based on undef value]
i32 %sext = #x00000000 (0)
i32 %#1 = #x00000000 (0)	[based on undef value]
i32 %mul = #x00000000 (0)

Target:
i16 %ashr = #x0018 (24)
i16 %narrow = #xf400 (62464, -3072)
i32 %mul = poison
Source value: #x00000000 (0)
Target value: poison


----------------------------------------
define <2 x i32> @test8_vec.2(<2 x i16> %V) {
#0:
  %ashr = ashr <2 x i16> %V, { 8, 8 }
  %sext = sext <2 x i16> %ashr to <2 x i32>
  %#1 = sext <2 x i16> %ashr to <2 x i32>
  %mul = mul <2 x i32> %sext, %#1
  ret <2 x i32> %mul
}
=>
define <2 x i32> @test8_vec.2(<2 x i16> %V) {
#0:
  %ashr = ashr <2 x i16> %V, { 8, 8 }
  %narrow = mul nsw <2 x i16> %ashr, %ashr
  %mul = zext nneg <2 x i16> %narrow to <2 x i32>
  ret <2 x i32> %mul
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
<2 x i16> %V = < #x0000 (0), undef >

Source:
<2 x i16> %ashr = < #x0000 (0), #x0000 (0)	[based on undef value] >
<2 x i32> %sext = < #x00000000 (0), #x00000000 (0) >
<2 x i32> %#1 = < #x00000000 (0), #x00000000 (0)	[based on undef value] >
<2 x i32> %mul = < #x00000000 (0), #x00000000 (0) >

Target:
<2 x i16> %ashr = < #x0000 (0), #xff80 (65408, -128) >
<2 x i16> %narrow = < #x0000 (0), #xfc00 (64512, -1024) >
<2 x i32> %mul = < #x00000000 (0), poison >
Source value: < #x00000000 (0), #x00000000 (0) >
Target value: < #x00000000 (0), poison >

Summary:
  0 correct transformations
  2 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

1 participant