Skip to content

Commit ba11cc2

Browse files
committed
[X86] Add missed type extension and truncation during combine
Type extension and truncation is missed when combining loads and stores for ptr32 and ptr64. Closes #66873
1 parent b186f1f commit ba11cc2

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -49820,9 +49820,9 @@ static SDValue combineLoad(SDNode *N, SelectionDAG &DAG,
4982049820
if (PtrVT != Ld->getBasePtr().getSimpleValueType()) {
4982149821
SDValue Cast =
4982249822
DAG.getAddrSpaceCast(dl, PtrVT, Ld->getBasePtr(), AddrSpace, 0);
49823-
return DAG.getLoad(RegVT, dl, Ld->getChain(), Cast, Ld->getPointerInfo(),
49824-
Ld->getOriginalAlign(),
49825-
Ld->getMemOperand()->getFlags());
49823+
return DAG.getExtLoad(Ext, dl, RegVT, Ld->getChain(), Cast,
49824+
Ld->getPointerInfo(), MemVT, Ld->getOriginalAlign(),
49825+
Ld->getMemOperand()->getFlags());
4982649826
}
4982749827
}
4982849828

@@ -50324,9 +50324,10 @@ static SDValue combineStore(SDNode *N, SelectionDAG &DAG,
5032450324
if (PtrVT != St->getBasePtr().getSimpleValueType()) {
5032550325
SDValue Cast =
5032650326
DAG.getAddrSpaceCast(dl, PtrVT, St->getBasePtr(), AddrSpace, 0);
50327-
return DAG.getStore(St->getChain(), dl, StoredVal, Cast,
50328-
St->getPointerInfo(), St->getOriginalAlign(),
50329-
St->getMemOperand()->getFlags(), St->getAAInfo());
50327+
return DAG.getTruncStore(
50328+
St->getChain(), dl, StoredVal, Cast, St->getPointerInfo(), StVT,
50329+
St->getOriginalAlign(), St->getMemOperand()->getFlags(),
50330+
St->getAAInfo());
5033050331
}
5033150332
}
5033250333

llvm/test/CodeGen/X86/mixed-ptr-sizes.ll

+15-6
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ define i64 @test_load_sptr32_zext_i64(ptr addrspace(270) %i) {
261261
; CHECK-LABEL: test_load_sptr32_zext_i64:
262262
; CHECK: # %bb.0: # %entry
263263
; CHECK-NEXT: movslq %ecx, %rax
264-
; CHECK-NEXT: movq (%rax), %rax
264+
; CHECK-NEXT: movl (%rax), %eax
265265
; CHECK-NEXT: retq
266266
;
267267
; CHECK-O0-LABEL: test_load_sptr32_zext_i64:
@@ -278,11 +278,20 @@ entry:
278278
}
279279

280280
define void @test_store_sptr32_trunc_i1(ptr addrspace(270) %s, i32 %i) {
281-
; ALL-LABEL: test_store_sptr32_trunc_i1:
282-
; ALL: # %bb.0: # %entry
283-
; ALL-NEXT: movslq %ecx, %rax
284-
; ALL-NEXT: movl %edx, (%rax)
285-
; ALL-NEXT: retq
281+
; CHECK-LABEL: test_store_sptr32_trunc_i1:
282+
; CHECK: # %bb.0: # %entry
283+
; CHECK-NEXT: movslq %ecx, %rax
284+
; CHECK-NEXT: andl $1, %edx
285+
; CHECK-NEXT: movb %dl, (%rax)
286+
; CHECK-NEXT: retq
287+
;
288+
; CHECK-O0-LABEL: test_store_sptr32_trunc_i1:
289+
; CHECK-O0: # %bb.0: # %entry
290+
; CHECK-O0-NEXT: movslq %ecx, %rax
291+
; CHECK-O0-NEXT: andl $1, %edx
292+
; CHECK-O0-NEXT: movb %dl, %cl
293+
; CHECK-O0-NEXT: movb %cl, (%rax)
294+
; CHECK-O0-NEXT: retq
286295
entry:
287296
%0 = trunc i32 %i to i1
288297
store i1 %0, ptr addrspace(270) %s

0 commit comments

Comments
 (0)