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 calculated a wrong insertelement instruction #84025

Closed
DianQK opened this issue Mar 5, 2024 · 4 comments · Fixed by #84027
Closed

InstCombine calculated a wrong insertelement instruction #84025

DianQK opened this issue Mar 5, 2024 · 4 comments · Fixed by #84027

Comments

@DianQK
Copy link
Member

DianQK commented Mar 5, 2024

I tried this IR:

define <4 x i32> @src(i32 %arg) {
  %i = zext i32 %arg to i64
  %i1 = shl i64 %i, 32
  %i2 = or i64 %i1, 65
  %i3 = zext i64 %i2 to i128
  %i4 = shl i128 %i3, 64
  %i5 = bitcast i128 %i4 to <4 x i32>
  ret <4 x i32> %i5
}

define <4 x i32> @tgt(i32 %arg) {
  %i5 = insertelement <4 x i32> <i32 0, i32 0, i32 0, i32 poison>, i32 %arg, i64 3
  ret <4 x i32> %i5
}

I expect src to be:

define <4 x i32> @src(i32 %arg) {
  %i5 = insertelement <4 x i32> <i32 0, i32 0, i32 65, i32 poison>, i32 %arg, i64 3
  ret <4 x i32> %i5
}

But I'm getting the same instructions as tgt.

Godbolt: https://llvm.godbolt.org/z/KnMEY4rTq
Alive2: https://alive2.llvm.org/ce/z/7FIJNi
From: rust-lang/rust#121996

@cbeuw
Copy link

cbeuw commented Mar 5, 2024

Looks like this bug is almost 11 years old: feb3471! Thanks for fixing

@DianQK
Copy link
Member Author

DianQK commented Mar 5, 2024

Looks like this bug is almost 11 years old: feb3471! Thanks for fixing

Based on my experience, we likely have many more latent bugs. :)

@DianQK
Copy link
Member Author

DianQK commented Mar 5, 2024

/cherry-pick e96c0c1

llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Mar 5, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 5, 2024

/pull-request #84080

cbeuw pushed a commit to cbeuw/llvm-project that referenced this issue Mar 6, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

4 participants