-
Notifications
You must be signed in to change notification settings - Fork 13.6k
InferAddressSpaces: Handle llvm.is.constant #102010
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
InferAddressSpaces: Handle llvm.is.constant #102010
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-backend-amdgpu @llvm/pr-subscribers-llvm-transforms Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/102010.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index 2ddf24be67702..67d4e7b5ee146 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -401,7 +401,8 @@ bool InferAddressSpacesImpl::rewriteIntrinsicOperands(IntrinsicInst *II,
II->setCalledFunction(NewDecl);
return true;
}
- case Intrinsic::prefetch: {
+ case Intrinsic::prefetch:
+ case Intrinsic::is_constant: {
Function *NewDecl =
Intrinsic::getDeclaration(M, II->getIntrinsicID(), {NewV->getType()});
II->setArgOperand(0, NewV);
@@ -426,6 +427,7 @@ void InferAddressSpacesImpl::collectRewritableIntrinsicOperands(
switch (IID) {
case Intrinsic::ptrmask:
case Intrinsic::objectsize:
+ case Intrinsic::is_constant:
appendsFlatAddressExpressionToPostorderStack(II->getArgOperand(0),
PostorderStack, Visited);
break;
diff --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/is.constant.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/is.constant.ll
new file mode 100644
index 0000000000000..767681a281792
--- /dev/null
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/is.constant.ll
@@ -0,0 +1,35 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s
+
+define i1 @is_constant_global_to_flat(ptr addrspace(1) %ptr) {
+; CHECK-LABEL: define i1 @is_constant_global_to_flat(
+; CHECK-SAME: ptr addrspace(1) [[PTR:%.*]]) {
+; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.p1(ptr addrspace(1) [[PTR]])
+; CHECK-NEXT: ret i1 [[RET]]
+;
+ %cast = addrspacecast ptr addrspace(1) %ptr to ptr
+ %ret = call i1 @llvm.is.constant.p0(ptr %cast)
+ ret i1 %ret
+}
+
+define i1 @is_constant_local_to_flat(ptr addrspace(3) %ptr) {
+; CHECK-LABEL: define i1 @is_constant_local_to_flat(
+; CHECK-SAME: ptr addrspace(3) [[PTR:%.*]]) {
+; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.p3(ptr addrspace(3) [[PTR]])
+; CHECK-NEXT: ret i1 [[RET]]
+;
+ %cast = addrspacecast ptr addrspace(3) %ptr to ptr
+ %ret = call i1 @llvm.is.constant.p0(ptr %cast)
+ ret i1 %ret
+}
+
+define i1 @is_constant_private_to_flat(ptr addrspace(5) %ptr) {
+; CHECK-LABEL: define i1 @is_constant_private_to_flat(
+; CHECK-SAME: ptr addrspace(5) [[PTR:%.*]]) {
+; CHECK-NEXT: [[RET:%.*]] = call i1 @llvm.is.constant.p5(ptr addrspace(5) [[PTR]])
+; CHECK-NEXT: ret i1 [[RET]]
+;
+ %cast = addrspacecast ptr addrspace(5) %ptr to ptr
+ %ret = call i1 @llvm.is.constant.p0(ptr %cast)
+ ret i1 %ret
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some tests where argument is not a pointer?
2dde2ad
to
227f60e
Compare
if (Ptr->getType()->isPtrOrPtrVectorTy()) { | ||
appendsFlatAddressExpressionToPostorderStack(Ptr, PostorderStack, | ||
Visited); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary braces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple lines is not listed as an excuse in the coding style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"However, braces should be used in cases where the omission of braces harm the readability and maintainability of the code."
and in my judgment this covers any situation with multiple lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could it hurt readability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because unlike a compiler I read by lines, and not statements.
The length of that section of the style guide is absurd. It should never be wrong to include braces. That's a lot simpler than parsing out whatever that is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should never be wrong to include braces.
Having to deal with google style that demands braces everywhere, and LLVM which does not want them, my personal choice is "whatever the style guide says". It may not always be a perfect choice, but it's not worth anyone's time to argue over specific instances, where the right choice is ambiguous or is a matter of personal preference. I wish we could delegate braces/no-braces decisions to clang-format, too, but I don't think it currently handles that.
I'd stick with the style guide defaults and either have the braces removed, or a comment added to the body. Perhaps, making the function name shorter, and avoiding line-wrapping would address your readability concerns about braces/no-braces here, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rule is so open ended it's useless. If clang-format doesn't do this, it's not a rule. I'm not wasting more CI cycles to touch this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo braces comment.
if (Ptr->getType()->isPtrOrPtrVectorTy()) { | ||
appendsFlatAddressExpressionToPostorderStack(Ptr, PostorderStack, | ||
Visited); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should never be wrong to include braces.
Having to deal with google style that demands braces everywhere, and LLVM which does not want them, my personal choice is "whatever the style guide says". It may not always be a perfect choice, but it's not worth anyone's time to argue over specific instances, where the right choice is ambiguous or is a matter of personal preference. I wish we could delegate braces/no-braces decisions to clang-format, too, but I don't think it currently handles that.
I'd stick with the style guide defaults and either have the braces removed, or a comment added to the body. Perhaps, making the function name shorter, and avoiding line-wrapping would address your readability concerns about braces/no-braces here, too.
From the clang-format documentation: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm RemoveBracesLLVM (Boolean) |
Thank you for the pointer. Unfortunately, it looks like there's a good reason it does not seem to be on by default:
|
0cd0fd7
to
fd7b3c2
Compare
227f60e
to
71a166f
Compare
Braces still there and no response to @Artem-B? I don't like that. |
I posted the reply yesterday but graphite apparently didn't submit it |
No description provided.