Skip to content
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
9 changes: 7 additions & 2 deletions src/backend/pass/emit/x86/x86_lower_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,14 @@ namespace rat {
case Opcode::FPTrunc:
fstpSse(vregFor(n), opWidth(n->getType()), x);
return;
case Opcode::SIToFP:
fild(x87SlotOf(n), s);
case Opcode::SIToFP: {
// fild reads all 64 bits, a narrower source loaded from memory is zero extended
VReg wide = fresh(detail::kGp);
mov(wide, s);
signExtBits(wide, intBits(st));
fild(x87SlotOf(n), wide);
return;
}
case Opcode::UIToFP:
emitUIntToX87(n, s, intBits(st));
return;
Expand Down
10 changes: 10 additions & 0 deletions src/compiler/test/correctness/custom/x87_from_narrow_int_noopt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// expect: 1
// passes:

// a negative int read back from memory, converted to long double
long double widen(int s) {
int* p = &s;
return *p;
}

int main(void) { return widen(-1) == -1.0L; }
Loading