Skip to content

Commit 0a3ee7d

Browse files
[PowerPC] fix bug affecting float to int32 conversion on LE PowerPC (llvm#150194)
When moving fcti results from float registers to normal registers through memory, even though MPI was adjusted to account for endianness, FIPtr was always adjusted for big-endian, which caused loads of wrong half of a value in little-endian mode.
1 parent fea7e69 commit 0a3ee7d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8505,10 +8505,11 @@ void PPCTargetLowering::LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
85058505

85068506
// Result is a load from the stack slot. If loading 4 bytes, make sure to
85078507
// add in a bias on big endian.
8508-
if (Op.getValueType() == MVT::i32 && !i32Stack) {
8508+
if (Op.getValueType() == MVT::i32 && !i32Stack &&
8509+
!Subtarget.isLittleEndian()) {
85098510
FIPtr = DAG.getNode(ISD::ADD, dl, FIPtr.getValueType(), FIPtr,
85108511
DAG.getConstant(4, dl, FIPtr.getValueType()));
8511-
MPI = MPI.getWithOffset(Subtarget.isLittleEndian() ? 0 : 4);
8512+
MPI = MPI.getWithOffset(4);
85128513
}
85138514

85148515
RLI.Chain = Chain;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: llc < %s -mcpu=440 -mtriple=ppc32le-unknown-unknown | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
2+
; RUN: llc < %s -mcpu=440 -mtriple=ppc32-unknown-unknown | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
3+
4+
define i32 @foo(double %a) {
5+
; CHECK-LABEL: foo:
6+
; CHECK-DAG: fctiwz [[FPR_1_i:[0-9]+]], {{[0-9]+}}
7+
; CHECK-DAG: stfd [[FPR_1_i]], [[#%u,VAL1_ADDR:]](1)
8+
; CHECK-LE-DAG: lwz {{[0-9]+}}, [[#%u,== VAL1_ADDR]](1)
9+
; CHECK-BE-DAG: lwz {{[0-9]+}}, [[#%u,== VAL1_ADDR + 4]](1)
10+
; CHECK-DAG: fctiwz [[FPR_2:[0-9]+]], {{[0-9]+}}
11+
; CHECK-DAG: stfd [[FPR_2]], [[#%u,VAL2_ADDR:]](1)
12+
; CHECK-LE-DAG: lwz {{[0-9]+}}, [[#%u,== VAL2_ADDR]](1)
13+
; CHECK-BE-DAG: lwz {{[0-9]+}}, [[#%u,== VAL2_ADDR + 4]](1)
14+
entry:
15+
%tmp.1 = fptoui double %a to i32 ; <i32> [#uses=1]
16+
ret i32 %tmp.1
17+
}

0 commit comments

Comments
 (0)