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

[RISC-V] i128 shift on RV32 calls __ashldi3 with out-of-range shift #57988

Open
Amanieu opened this issue Sep 26, 2022 · 4 comments
Open

[RISC-V] i128 shift on RV32 calls __ashldi3 with out-of-range shift #57988

Amanieu opened this issue Sep 26, 2022 · 4 comments
Assignees

Comments

@Amanieu
Copy link
Contributor

Amanieu commented Sep 26, 2022

LLVM IR:

define i128 @shift_128(i32 %0) #0 {
  %2 = zext i32 %0 to i128
  %3 = shl i128 1, %2
  ret i128 %3
}

attributes #0 = { minsize nounwind optsize }

This generates this call to __ashldi3 at the start of the function. The value in a2 passed to __ashldi3 is out of range if the shift amount is less than 64. The documentation for __ashldi3 explicitly says that the shift amount must be between 0 and 63 inclusive.

	addi	a2, a1, -64
	li	a0, 1
	li	a1, 0
	call	__ashldi3@plt
@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2022

@llvm/issue-subscribers-backend-risc-v

@jrtc27
Copy link
Collaborator

jrtc27 commented Sep 26, 2022

This seems to be a generic problem in DAGTypeLegalizer::ExpandShiftWithUnknownAmountBit, it assumes it can just blindly select both cases (a1 < 64, a1 >= 64) rather than actually having a condition based on it. This is only correct in the case that those themselves are well-defined (poison allowed).

@jrtc27
Copy link
Collaborator

jrtc27 commented Sep 26, 2022

(https://godbolt.org/z/Yd1dqr9nn shows the problem (they look more different only due to scheduling) on i386, arm and riscv32).

@topperc topperc self-assigned this Sep 26, 2022
@topperc
Copy link
Collaborator

topperc commented Sep 26, 2022

Candidate patch https://reviews.llvm.org/D134684

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

5 participants