[llvm] 0b4af3a - [llvm][SelectionDAG] Relax llvm.ptrmask's size check on arm64_32 (#94125)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 15:26:33 PDT 2024
Author: Jon Roelofs
Date: 2024-06-03T15:26:30-07:00
New Revision: 0b4af3a5f4de61552000e4a864f63f2002cc525b
URL: https://github.com/llvm/llvm-project/commit/0b4af3a5f4de61552000e4a864f63f2002cc525b
DIFF: https://github.com/llvm/llvm-project/commit/0b4af3a5f4de61552000e4a864f63f2002cc525b.diff
LOG: [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
Added:
llvm/test/CodeGen/AArch64/lower-ptrmask-arm64_32.ll
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index c7e0c62ec1263..72678c1a4c645 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -7844,9 +7844,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
diff erent 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;
}
diff --git a/llvm/test/CodeGen/AArch64/lower-ptrmask-arm64_32.ll b/llvm/test/CodeGen/AArch64/lower-ptrmask-arm64_32.ll
new file mode 100644
index 0000000000000..3f0a2640b6ad8
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/lower-ptrmask-arm64_32.ll
@@ -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
+}
More information about the llvm-commits
mailing list