Skip to content

Commit 4e8dfcb

Browse files
committed
[NVPTX] Remove incorrect elimination of CopyToReg
Fixes miscompilation introduced by llvm#126337 llvm#126337 (comment)
1 parent ff5784b commit 4e8dfcb

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4979,8 +4979,6 @@ combineUnpackingMovIntoLoad(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
49794979
if (!NVPTX::isPackedVectorTy(ElementVT) || ElementVT == MVT::v4i8)
49804980
return SDValue();
49814981

4982-
SmallVector<SDNode *> DeadCopyToRegs;
4983-
49844982
// Check whether all outputs are either used by an extractelt or are
49854983
// glue/chain nodes
49864984
if (!all_of(N->uses(), [&](SDUse &U) {
@@ -5008,12 +5006,6 @@ combineUnpackingMovIntoLoad(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
50085006
return !U.getUser()->use_empty();
50095007
}
50105008

5011-
// Handle CopyToReg nodes that will become dead after our replacement
5012-
if (U.getUser()->getOpcode() == ISD::CopyToReg) {
5013-
DeadCopyToRegs.push_back(U.getUser());
5014-
return true;
5015-
}
5016-
50175009
// Otherwise, this use prevents us from splitting a value.
50185010
return false;
50195011
}))
@@ -5080,10 +5072,6 @@ combineUnpackingMovIntoLoad(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
50805072
for (unsigned I : seq(NewLoad->getNumValues() - NewNumOutputs))
50815073
Results.push_back(NewLoad.getValue(NewNumOutputs + I));
50825074

5083-
// Remove dead CopyToReg nodes by folding them into the chain they reference
5084-
for (SDNode *CTR : DeadCopyToRegs)
5085-
DCI.CombineTo(CTR, CTR->getOperand(0));
5086-
50875075
return DCI.DAG.getMergeValues(Results, DL);
50885076
}
50895077

@@ -6420,4 +6408,4 @@ void NVPTXTargetLowering::computeKnownBitsForTargetNode(
64206408
default:
64216409
break;
64226410
}
6423-
}
6411+
}

llvm/test/CodeGen/NVPTX/pr126337.ll

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_70 | FileCheck %s
3+
; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_70 | %ptxas-verify %}
4+
5+
; This IR should compile without triggering assertions in LICM
6+
; when the CopyToReg from %0 in the first BB gets eliminated
7+
; but we still use its result in the second BB.
8+
; Technically the problem happens in MIR, but there are multiple
9+
; passes involved, so testing with the IR reproducer is more convenient.
10+
; https://github.com/llvm/llvm-project/pull/126337#issuecomment-3081431594
11+
12+
target datalayout = "e-p6:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
13+
target triple = "nvptx64-nvidia-cuda"
14+
15+
define ptx_kernel void @Equal_GPU_DT_COMPLEX64_DT_BOOL_kernel(<2 x float> %0) {
16+
; CHECK-LABEL: Equal_GPU_DT_COMPLEX64_DT_BOOL_kernel(
17+
; CHECK: {
18+
; CHECK-NEXT: .reg .pred %p<2>;
19+
; CHECK-NEXT: .reg .b16 %rs<2>;
20+
; CHECK-NEXT: .reg .b32 %r<2>;
21+
; CHECK-NEXT: .reg .b64 %rd<3>;
22+
; CHECK-EMPTY:
23+
; CHECK-NEXT: // %bb.0: // %.preheader15
24+
; CHECK-NEXT: ld.param.b64 %rd1, [Equal_GPU_DT_COMPLEX64_DT_BOOL_kernel_param_0];
25+
; CHECK-NEXT: { .reg .b32 tmp; mov.b64 {%r1, tmp}, %rd1; }
26+
; CHECK-NEXT: setp.eq.f32 %p1, %r1, 0f00000000;
27+
; CHECK-NEXT: selp.b16 %rs1, 1, 0, %p1;
28+
; CHECK-NEXT: $L__BB0_1: // =>This Inner Loop Header: Depth=1
29+
; CHECK-NEXT: mov.b64 %rd2, 0;
30+
; CHECK-NEXT: st.b8 [%rd2], %rs1;
31+
; CHECK-NEXT: bra.uni $L__BB0_1;
32+
.preheader15:
33+
br label %1
34+
35+
1: ; preds = %1, %.preheader15
36+
%2 = fcmp oeq <2 x float> %0, zeroinitializer
37+
%3 = extractelement <2 x i1> %2, i64 0
38+
store i1 %3, ptr null, align 4
39+
br label %1
40+
}
41+

0 commit comments

Comments
 (0)