Skip to content

Commit 255f826

Browse files
authored
[X86] Fix value-extending/truncating loads and stores of __ptr32/__ptr64 pointers (#67168)
The value extension and truncation were missed during casting __ptr32/__ptr64 pointers to the default address space. Closes #66873
1 parent b05dbc4 commit 255f826

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49835,9 +49835,9 @@ static SDValue combineLoad(SDNode *N, SelectionDAG &DAG,
4983549835
if (PtrVT != Ld->getBasePtr().getSimpleValueType()) {
4983649836
SDValue Cast =
4983749837
DAG.getAddrSpaceCast(dl, PtrVT, Ld->getBasePtr(), AddrSpace, 0);
49838-
return DAG.getLoad(RegVT, dl, Ld->getChain(), Cast, Ld->getPointerInfo(),
49839-
Ld->getOriginalAlign(),
49840-
Ld->getMemOperand()->getFlags());
49838+
return DAG.getExtLoad(Ext, dl, RegVT, Ld->getChain(), Cast,
49839+
Ld->getPointerInfo(), MemVT, Ld->getOriginalAlign(),
49840+
Ld->getMemOperand()->getFlags());
4984149841
}
4984249842
}
4984349843

@@ -50339,9 +50339,10 @@ static SDValue combineStore(SDNode *N, SelectionDAG &DAG,
5033950339
if (PtrVT != St->getBasePtr().getSimpleValueType()) {
5034050340
SDValue Cast =
5034150341
DAG.getAddrSpaceCast(dl, PtrVT, St->getBasePtr(), AddrSpace, 0);
50342-
return DAG.getStore(St->getChain(), dl, StoredVal, Cast,
50343-
St->getPointerInfo(), St->getOriginalAlign(),
50344-
St->getMemOperand()->getFlags(), St->getAAInfo());
50342+
return DAG.getTruncStore(
50343+
St->getChain(), dl, StoredVal, Cast, St->getPointerInfo(), StVT,
50344+
St->getOriginalAlign(), St->getMemOperand()->getFlags(),
50345+
St->getAAInfo());
5034550346
}
5034650347
}
5034750348

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

Lines changed: 15 additions & 6 deletions
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)