Skip to content

[llvm][SelectionDAG] Relax llvm.ptrmask's size check on arm64_32 #94125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7842,9 +7842,19 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
SDValue Ptr = getValue(I.getOperand(0));
SDValue Mask = getValue(I.getOperand(1));

EVT PtrVT = Ptr.getValueType();
assert(PtrVT == Mask.getValueType() &&
"Pointers with different index type are not supported by SDAG");
// On arm64_32, pointers are 32 bits when stored in memory, but
// zero-extended to 64 bits when in registers. Thus the mask is 32 bits to
// match the index type, but the pointer is 64 bits, so the the mask must be
// zero-extended up to 64 bits to match the pointer.
EVT PtrVT =
TLI.getValueType(DAG.getDataLayout(), I.getOperand(0)->getType());
EVT MemVT =
TLI.getMemValueType(DAG.getDataLayout(), I.getOperand(0)->getType());
assert(PtrVT == Ptr.getValueType());
assert(MemVT == Mask.getValueType());
if (MemVT != PtrVT)
Mask = DAG.getPtrExtOrTrunc(Mask, sdl, PtrVT);

setValue(&I, DAG.getNode(ISD::AND, sdl, PtrVT, Ptr, Mask));
return;
}
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/CodeGen/AArch64/lower-ptrmask-arm64_32.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=arm64_32-apple-watchos2.0.0 %s -o - | FileCheck %s

define ptr @issue94075(ptr %p) {
; CHECK-LABEL: issue94075:
; CHECK: ; %bb.0: ; %entry
; CHECK-NEXT: and x0, x0, #0xfffffff8
; CHECK-NEXT: ret
entry:
%rdar125263567 = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 4294967288)
ret ptr %rdar125263567
}
Loading