[llvm] [PowerPC] fix bug affecting float to int32 conversion on LE PowerPC (PR #150194)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 23 02:12:49 PDT 2025


https://github.com/DanilaZhebryakov created https://github.com/llvm/llvm-project/pull/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.

>From 041ff9880939fddcd9a36009d32b234e8d4acc5b Mon Sep 17 00:00:00 2001
From: Danila Zhebryakov <d.zhebryakov at yandex.ru>
Date: Wed, 23 Jul 2025 12:04:17 +0300
Subject: [PATCH] [PowerPC] fix bug affecting float to int32 conversion on some
 PowerPC CPUs

---
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index 459525ed4ee9a..3974d726620b7 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -8457,10 +8457,10 @@ void PPCTargetLowering::LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
 
   // Result is a load from the stack slot.  If loading 4 bytes, make sure to
   // add in a bias on big endian.
-  if (Op.getValueType() == MVT::i32 && !i32Stack) {
+  if (Op.getValueType() == MVT::i32 && !i32Stack && !Subtarget.isLittleEndian()) {
     FIPtr = DAG.getNode(ISD::ADD, dl, FIPtr.getValueType(), FIPtr,
                         DAG.getConstant(4, dl, FIPtr.getValueType()));
-    MPI = MPI.getWithOffset(Subtarget.isLittleEndian() ? 0 : 4);
+    MPI = MPI.getWithOffset(4);
   }
 
   RLI.Chain = Chain;



More information about the llvm-commits mailing list