Skip to content

Commit 0b4af3a

Browse files
authored
[llvm][SelectionDAG] Relax llvm.ptrmask's size check on arm64_32 (#94125)
Since pointers in memory, as well as the index type are both 32 bits, but in registers pointers are 64 bits, the mask generated by llvm.ptrmask needs to be zero-extended. Fixes: #94075 Fixes: rdar://125263567
1 parent d03cd05 commit 0b4af3a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7844,9 +7844,19 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
78447844
SDValue Ptr = getValue(I.getOperand(0));
78457845
SDValue Mask = getValue(I.getOperand(1));
78467846

7847-
EVT PtrVT = Ptr.getValueType();
7848-
assert(PtrVT == Mask.getValueType() &&
7849-
"Pointers with different index type are not supported by SDAG");
7847+
// On arm64_32, pointers are 32 bits when stored in memory, but
7848+
// zero-extended to 64 bits when in registers. Thus the mask is 32 bits to
7849+
// match the index type, but the pointer is 64 bits, so the the mask must be
7850+
// zero-extended up to 64 bits to match the pointer.
7851+
EVT PtrVT =
7852+
TLI.getValueType(DAG.getDataLayout(), I.getOperand(0)->getType());
7853+
EVT MemVT =
7854+
TLI.getMemValueType(DAG.getDataLayout(), I.getOperand(0)->getType());
7855+
assert(PtrVT == Ptr.getValueType());
7856+
assert(MemVT == Mask.getValueType());
7857+
if (MemVT != PtrVT)
7858+
Mask = DAG.getPtrExtOrTrunc(Mask, sdl, PtrVT);
7859+
78507860
setValue(&I, DAG.getNode(ISD::AND, sdl, PtrVT, Ptr, Mask));
78517861
return;
78527862
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=arm64_32-apple-watchos2.0.0 %s -o - | FileCheck %s
3+
4+
define ptr @issue94075(ptr %p) {
5+
; CHECK-LABEL: issue94075:
6+
; CHECK: ; %bb.0: ; %entry
7+
; CHECK-NEXT: and x0, x0, #0xfffffff8
8+
; CHECK-NEXT: ret
9+
entry:
10+
%rdar125263567 = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 4294967288)
11+
ret ptr %rdar125263567
12+
}

0 commit comments

Comments
 (0)