Skip to content

Commit 2ef553c

Browse files
authored
InferAddressSpaces: Handle llvm.is.constant (#102010)
1 parent 47fc4c3 commit 2ef553c

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ bool InferAddressSpacesImpl::rewriteIntrinsicOperands(IntrinsicInst *II,
401401
II->setCalledFunction(NewDecl);
402402
return true;
403403
}
404-
case Intrinsic::prefetch: {
404+
case Intrinsic::prefetch:
405+
case Intrinsic::is_constant: {
405406
Function *NewDecl =
406407
Intrinsic::getDeclaration(M, II->getIntrinsicID(), {NewV->getType()});
407408
II->setArgOperand(0, NewV);
@@ -429,6 +430,15 @@ void InferAddressSpacesImpl::collectRewritableIntrinsicOperands(
429430
appendsFlatAddressExpressionToPostorderStack(II->getArgOperand(0),
430431
PostorderStack, Visited);
431432
break;
433+
case Intrinsic::is_constant: {
434+
Value *Ptr = II->getArgOperand(0);
435+
if (Ptr->getType()->isPtrOrPtrVectorTy()) {
436+
appendsFlatAddressExpressionToPostorderStack(Ptr, PostorderStack,
437+
Visited);
438+
}
439+
440+
break;
441+
}
432442
case Intrinsic::masked_load:
433443
case Intrinsic::masked_gather:
434444
case Intrinsic::prefetch:
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s
3+
4+
define i1 @is_constant_global_to_flat(ptr addrspace(1) %ptr) {
5+
; CHECK-LABEL: define i1 @is_constant_global_to_flat(
6+
; CHECK-SAME: ptr addrspace(1) [[PTR:%.*]]) {
7+
; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.p1(ptr addrspace(1) [[PTR]])
8+
; CHECK-NEXT: ret i1 [[RET]]
9+
;
10+
%cast = addrspacecast ptr addrspace(1) %ptr to ptr
11+
%ret = call i1 @llvm.is.constant.p0(ptr %cast)
12+
ret i1 %ret
13+
}
14+
15+
define i1 @is_constant_local_to_flat(ptr addrspace(3) %ptr) {
16+
; CHECK-LABEL: define i1 @is_constant_local_to_flat(
17+
; CHECK-SAME: ptr addrspace(3) [[PTR:%.*]]) {
18+
; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.p3(ptr addrspace(3) [[PTR]])
19+
; CHECK-NEXT: ret i1 [[RET]]
20+
;
21+
%cast = addrspacecast ptr addrspace(3) %ptr to ptr
22+
%ret = call i1 @llvm.is.constant.p0(ptr %cast)
23+
ret i1 %ret
24+
}
25+
26+
define i1 @is_constant_private_to_flat(ptr addrspace(5) %ptr) {
27+
; CHECK-LABEL: define i1 @is_constant_private_to_flat(
28+
; CHECK-SAME: ptr addrspace(5) [[PTR:%.*]]) {
29+
; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.p5(ptr addrspace(5) [[PTR]])
30+
; CHECK-NEXT: ret i1 [[RET]]
31+
;
32+
%cast = addrspacecast ptr addrspace(5) %ptr to ptr
33+
%ret = call i1 @llvm.is.constant.p0(ptr %cast)
34+
ret i1 %ret
35+
}
36+
37+
define i1 @is_constant_private_to_flat_v2(<2 x ptr addrspace(5)> %ptr) {
38+
; CHECK-LABEL: define i1 @is_constant_private_to_flat_v2(
39+
; CHECK-SAME: <2 x ptr addrspace(5)> [[PTR:%.*]]) {
40+
; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.v2p5(<2 x ptr addrspace(5)> [[PTR]])
41+
; CHECK-NEXT: ret i1 [[RET]]
42+
;
43+
%cast = addrspacecast <2 x ptr addrspace(5)> %ptr to <2 x ptr>
44+
%ret = call i1 @llvm.is.constant.v2p0(<2 x ptr> %cast)
45+
ret i1 %ret
46+
}
47+
48+
define i1 @is_constant_i32(i32 %val) {
49+
; CHECK-LABEL: define i1 @is_constant_i32(
50+
; CHECK-SAME: i32 [[VAL:%.*]]) {
51+
; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.i32(i32 [[VAL]])
52+
; CHECK-NEXT: ret i1 [[RET]]
53+
;
54+
%ret = call i1 @llvm.is.constant.i32(i32 %val)
55+
ret i1 %ret
56+
}

0 commit comments

Comments
 (0)