[llvm] [FunctionAttrs] Improve handling of alias-preserving intrinsic calls (PR #68453)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 01:43:48 PDT 2023


================
@@ -654,6 +654,17 @@ determinePointerAccessAttrs(Argument *A,
       // must be a data operand (e.g. argument or operand bundle)
       const unsigned UseIndex = CB.getDataOperandNo(U);
 
+      // Some intrinsics (for instance ptrmask) do not capture their results,
+      // but return results thas alias their pointer argument, and thus should
+      // be handled like GEP or addrspacecast above.
+      if (isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(
+              &CB, /*MustPreserveNullness=*/false)) {
+        for (Use &UU : CB.uses())
+          if (Visited.insert(&UU).second)
+            Worklist.push_back(&UU);
+        continue;
----------------
nikic wrote:

I think strictly speaking this continue here should be replaced by an `else` after the if.

That is, this code is a replacement for the capture check directly below it, but it does not replace the memory checks further down.

I don't think your code is *currently* incorrect because all functions in isIntrinsicReturningPointerAliasingArgumentWithoutCapturing() don't perform memory accesses on the pointer either, but as that isn't part of the contract of that functions, it may be that it becomes incorrect in the future.

https://github.com/llvm/llvm-project/pull/68453


More information about the llvm-commits mailing list