Skip to content

[RISCV] Always use signed APSInt in getExactInteger. #84070

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

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3233,7 +3233,9 @@ struct VIDSequence {

static std::optional<uint64_t> getExactInteger(const APFloat &APF,
uint32_t BitWidth) {
APSInt ValInt(BitWidth, !APF.isNegative());
// We will use a SINT_TO_FP to materialize this constant so we should use a
// signed APSInt here.
APSInt ValInt(BitWidth, /*IsUnsigned*/ false);
// We use an arbitrary rounding mode here. If a floating-point is an exact
// integer (e.g., 1.0), the rounding mode does not affect the output value. If
// the rounding mode changes the output value, then it is not an exact
Expand Down
11 changes: 5 additions & 6 deletions llvm/test/CodeGen/RISCV/rvv/vle_vid-vfcvt.ll
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,15 @@ entry:
ret void
}

; FIXME: This is miscompiled. This will create -2147483648.0 instead of
; 2147483648.0 for the 4th element.
; Make sure we don't try to use vid+vsll+vfcvt. We previously flipped the sign
; of 2147483648.0.
define void @foo_9(ptr nocapture noundef writeonly %t) {
; CHECK-LABEL: foo_9:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: lui a1, %hi(.LCPI8_0)
; CHECK-NEXT: addi a1, a1, %lo(.LCPI8_0)
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
; CHECK-NEXT: vid.v v8
; CHECK-NEXT: vsll.vi v8, v8, 31
; CHECK-NEXT: vrsub.vi v8, v8, 0
; CHECK-NEXT: vfcvt.f.x.v v8, v8
; CHECK-NEXT: vle32.v v8, (a1)
; CHECK-NEXT: vse32.v v8, (a0)
; CHECK-NEXT: ret
entry:
Expand Down