Skip to content

Commit cf37657

Browse files
committed
[InstSimplify] Support ptrtoaddr in ptrmask fold
Treat it the same way as ptrtoint. ptrmask only operates on the address bits of the pointer.
1 parent 90cbc37 commit cf37657

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6644,7 +6644,7 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
66446644
"Invalid mask width");
66456645
// If index-width (mask size) is less than pointer-size then mask is
66466646
// 1-extended.
6647-
if (match(Op1, m_PtrToInt(m_Specific(Op0))))
6647+
if (match(Op1, m_PtrToIntOrAddr(m_Specific(Op0))))
66486648
return Op0;
66496649

66506650
// NOTE: We may have attributes associated with the return value of the

llvm/test/Transforms/InstSimplify/ptrmask.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ define ptr addrspace(1) @ptrmask_simplify_ptrmask_i32(ptr addrspace(1) %p) {
158158
ret ptr addrspace(1) %r
159159
}
160160

161+
define ptr @ptrmask_simplify_ptrtoaddr(ptr %p) {
162+
; CHECK-LABEL: define ptr @ptrmask_simplify_ptrtoaddr
163+
; CHECK-SAME: (ptr [[P:%.*]]) {
164+
; CHECK-NEXT: ret ptr [[P]]
165+
;
166+
%m = ptrtoaddr ptr %p to i64
167+
%r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
168+
ret ptr %r
169+
}
170+
171+
define ptr addrspace(1) @ptrmask_simplify_ptrtoaddr_i32(ptr addrspace(1) %p) {
172+
; CHECK-LABEL: define ptr addrspace(1) @ptrmask_simplify_ptrtoaddr_i32
173+
; CHECK-SAME: (ptr addrspace(1) [[P:%.*]]) {
174+
; CHECK-NEXT: ret ptr addrspace(1) [[P]]
175+
;
176+
%m = ptrtoaddr ptr addrspace(1) %p to i32
177+
%r = call ptr addrspace(1) @llvm.ptrmask.p1.i32(ptr addrspace(1) %p, i32 %m)
178+
ret ptr addrspace(1) %r
179+
}
180+
161181
define ptr @ptrmask_simplify_aligned_unused(ptr align 64 %p) {
162182
; CHECK-LABEL: define ptr @ptrmask_simplify_aligned_unused
163183
; CHECK-SAME: (ptr align 64 [[P:%.*]]) {

0 commit comments

Comments
 (0)