[llvm] d283ad8 - [NVPTX] Preserve the load chain when custom-lowering i1 loads (#230497)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 10 20:05:38 PDT 2026
Author: actink
Date: 2026-10-11T11:05:33+08:00
New Revision: d283ad857cbfc1d890c1fdc0a829574a84aabe75
URL: https://github.com/llvm/llvm-project/commit/d283ad857cbfc1d890c1fdc0a829574a84aabe75
DIFF: https://github.com/llvm/llvm-project/commit/d283ad857cbfc1d890c1fdc0a829574a84aabe75.diff
LOG: [NVPTX] Preserve the load chain when custom-lowering i1 loads (#230497)
lowerLOADi1() rewrites an i1 load into a zext load to i16 plus a
truncate, and returns the (value, chain) pair as a MERGE_VALUES node.
LegalizeLoadOps installs that pair with
RChain = Res.getValue(1);
DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), RChain);
so the second value of the MERGE_VALUES becomes the replacement for the
original load's chain result. Returning LD->getChain() therefore rewires
every memory operation that followed the original load to that load's
predecessor, and leaves the new zext load's chain result with no users.
The ordering edge between the new load and those memory operations is
dropped, so nothing in the DAG keeps them in order beyond whatever data
dependency happens to exist between them.
Return newLD.getValue(1) instead, so the edge is preserved.
Added:
llvm/test/CodeGen/NVPTX/i1-load-chain.ll
Modified:
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index 2a06c99f66ca9..30b2dddc305fe 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -4030,7 +4030,7 @@ static SDValue lowerLOADi1(LoadSDNode *LD, SelectionDAG &DAG) {
// The legalizer (the caller) is expecting two values from the legalized
// load, so we build a MergeValues node for it. See ExpandUnalignedLoad()
// in LegalizeDAG.cpp which also uses MergeValues.
- return DAG.getMergeValues({result, LD->getChain()}, dl);
+ return DAG.getMergeValues({result, newLD.getValue(1)}, dl);
}
SDValue NVPTXTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
diff --git a/llvm/test/CodeGen/NVPTX/i1-load-chain.ll b/llvm/test/CodeGen/NVPTX/i1-load-chain.ll
new file mode 100644
index 0000000000000..13b108c76bdf8
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/i1-load-chain.ll
@@ -0,0 +1,20 @@
+; RUN: llc < %s -mtriple=nvptx64 -debug-only=isel 2>&1 | FileCheck %s
+; REQUIRES: asserts
+;
+; An i1 load is custom-lowered to a zext load to i16 plus a truncate.
+; LegalizeLoadOps replaces the original load's chain result with the chain the
+; lowering returns, so the lowering must return the new load's chain: returning
+; the original one leaves the new load unordered with respect to everything
+; that followed the original load. The store to %p aliases the load, and its
+; stored value does not come from the load, so only the chain orders them.
+
+target triple = "nvptx64-nvidia-cuda"
+
+define void @foo(ptr %p, ptr %q) {
+; CHECK: [[LD:t[0-9]+]]: i16,ch = load<{{.*}}load (s8) from %ir.p{{.*}}
+; CHECK: store<(store (s8) into %ir.p), trunc to i8> [[LD]]:1,
+ %v = load i1, ptr %p
+ store i1 true, ptr %p
+ store i1 %v, ptr %q
+ ret void
+}
More information about the llvm-commits
mailing list