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

[CodeGen] x86_64 unable to select X86ISD::VSHLV/X86ISD::VSRLV on v32i1 #85681

Closed
DataCorrupted opened this issue Mar 18, 2024 · 4 comments
Closed
Assignees
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@DataCorrupted
Copy link
Member

Reproduction

https://godbolt.org/z/d4YWMP6cT

Same problem with emeraldrapids, sapphirerapids, or znver4.

@phoebewang Is this a bug or misuse? If it is a bug, I can help fix it.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 18, 2024

@llvm/issue-subscribers-backend-x86

Author: Peter Rong (DataCorrupted)

# Reproduction

https://godbolt.org/z/d4YWMP6cT

Same problem with emeraldrapids, sapphirerapids, or znver4.

@phoebewang Is this a bug or misuse? If it is a bug, I can help fix it.

@EugeneZelenko EugeneZelenko added crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:SelectionDAG SelectionDAGISel as well labels Mar 18, 2024
@phoebewang
Copy link
Contributor

@DataCorrupted shl on i1 type is allowed, but the result is UB if the second operator is not full of zeros. Nevertheless, a crash is always a bug. I think we may simply optimize a

%c = shl <32 x i1> %a, %b

to

%c = %a

Similarly to lshr/ashr https://godbolt.org/z/KcTo3h8cq

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 19, 2024

Alive2: https://alive2.llvm.org/ce/z/SdESbg

@RKSimon RKSimon self-assigned this Mar 19, 2024
@RKSimon
Copy link
Collaborator

RKSimon commented Mar 19, 2024

Reduced:

define i32 @PR85681(i32 %a0) {
  %v0 = bitcast i32 %a0 to <32 x i1>
  %s = shl <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, %v0
  %r = bitcast <32 x i1> %s to i32
  ret i32 %r
}

DataCorrupted added a commit to SecurityLab-UCD/llvm-project that referenced this issue Mar 19, 2024
`%c = shl <X x i1> %a, %b -> %c = %a`
As discussed in llvm#85681, this pattern is added to avoid cannot selection error.
Since shift one is either identical or UB, we consider it as identical and replace all uses of %c with %a.

Tests for shl, ashr, lshr are added.
This fixes llvm#85681.

Signed-off-by: Peter Rong <PeterRong96@gmail.com>
@EugeneZelenko EugeneZelenko removed the llvm:SelectionDAG SelectionDAGISel as well label Mar 19, 2024
chencha3 pushed a commit to chencha3/llvm-project that referenced this issue Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants