Skip to content

Commit 25b9ed6

Browse files
authored
[DAGCombine] Fix multi-use miscompile in load combine (llvm#81586)
The load combine replaces a number of original loads with one new loads and also replaces the output chains of the original loads with the output chain of the new load. This is incorrect if the original load is retained (due to multi-use), as it may get incorrectly reordered. Fix this by using makeEquivalentMemoryOrdering() instead, which will create a TokenFactor with both chains. Fixes llvm#80911.
1 parent 89c1bf1 commit 25b9ed6

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9252,7 +9252,7 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {
92529252

92539253
// Transfer chain users from old loads to the new load.
92549254
for (LoadSDNode *L : Loads)
9255-
DAG.ReplaceAllUsesOfValueWith(SDValue(L, 1), SDValue(NewLoad.getNode(), 1));
9255+
DAG.makeEquivalentMemoryOrdering(L, NewLoad);
92569256

92579257
if (!NeedsBswap)
92589258
return NewLoad;

llvm/test/CodeGen/X86/load-combine.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,6 @@ define i32 @zext_load_i32_by_i8_bswap_shl_16(ptr %arg) {
12831283
ret i32 %tmp8
12841284
}
12851285

1286-
; FIXME: This is a miscompile.
12871286
define i32 @pr80911_vector_load_multiuse(ptr %ptr, ptr %clobber) nounwind {
12881287
; CHECK-LABEL: pr80911_vector_load_multiuse:
12891288
; CHECK: # %bb.0:
@@ -1299,9 +1298,9 @@ define i32 @pr80911_vector_load_multiuse(ptr %ptr, ptr %clobber) nounwind {
12991298
;
13001299
; CHECK64-LABEL: pr80911_vector_load_multiuse:
13011300
; CHECK64: # %bb.0:
1301+
; CHECK64-NEXT: movl (%rdi), %ecx
13021302
; CHECK64-NEXT: movzwl (%rdi), %eax
13031303
; CHECK64-NEXT: movl $0, (%rsi)
1304-
; CHECK64-NEXT: movl (%rdi), %ecx
13051304
; CHECK64-NEXT: movl %ecx, (%rdi)
13061305
; CHECK64-NEXT: retq
13071306
%load = load <4 x i8>, ptr %ptr, align 16

0 commit comments

Comments
 (0)