[llvm-branch-commits] [llvm] release/22.x: [TargetLowering] Speculative fix for a non-determinism issue between different compilers. (#190219) (PR #190624)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Apr 6 09:11:30 PDT 2026


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/190624

Backport e2e5db840109e9a5d5bb190fcae350161a6e5481

Requested by: @topperc

>From 56b148c03fc0885d32a411adf1d347d48dc8680d Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 2 Apr 2026 12:12:28 -0700
Subject: [PATCH] [TargetLowering] Speculative fix for a non-determinism issue
 between different compilers. (#190219)

The evaluation order of function arguments is unspecified by the C++
standard. We had two getNode calls as function arguments which causes
the nodes to be created in a different order depending on the compiler
used. This patch moves them to their own variables to ensure they are
called in the same order on all compilers.

Possible fix for #190148.

(cherry picked from commit e2e5db840109e9a5d5bb190fcae350161a6e5481)
---
 llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index ee489f9fc74f9..b218b91c19cbb 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -11239,10 +11239,10 @@ void TargetLowering::forceExpandMultiply(SelectionDAG &DAG, const SDLoc &dl,
   // If HiLHS and HiRHS are set, multiply them by the opposite low part and add
   // the products to Hi.
   if (HiLHS) {
+    SDValue RHLL = DAG.getNode(ISD::MUL, dl, VT, HiRHS, LHS);
+    SDValue RLLH = DAG.getNode(ISD::MUL, dl, VT, RHS, HiLHS);
     Hi = DAG.getNode(ISD::ADD, dl, VT, Hi,
-                     DAG.getNode(ISD::ADD, dl, VT,
-                                 DAG.getNode(ISD::MUL, dl, VT, HiRHS, LHS),
-                                 DAG.getNode(ISD::MUL, dl, VT, RHS, HiLHS)));
+                     DAG.getNode(ISD::ADD, dl, VT, RHLL, RLLH));
   }
 }
 



More information about the llvm-branch-commits mailing list