[llvm] [InferAddressSpaces] Fix constant replace to avoid modifying other functions (PR #70611)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 30 00:02:40 PDT 2023


================
@@ -0,0 +1,40 @@
+; RUN: opt -assume-default-is-flat-addrspace -print-module-scope -print-after-all -S -disable-output -passes=infer-address-spaces <%s 2>&1 | FileCheck %s
+
+; CHECK: IR Dump After InferAddressSpacesPass on f2
+
+; Check that after running infer-address-spaces on f2, the redundant addrspace cast %x1 in f2 is gone.
+; CHECK-LABEL: define spir_func void @f2()
+; CHECK:         [[X:%.*]] = addrspacecast ptr addrspace(1) @x to ptr
+; CHECK-NEXT:    call spir_func void @f1(ptr noundef [[X]])
+
+; But it should not affect f3.
+; CHECK-LABEL: define spir_func void @f3()
+; CHECK:         %x1 = addrspacecast ptr addrspacecast (ptr addrspace(1) @x to ptr) to ptr addrspace(1)
+; CHECK-NEXT:    %x2 = addrspacecast ptr addrspace(1) %x1 to ptr
+; CHECK-NEXT:    call spir_func void @f1(ptr noundef %x2)
+
+; Ensure that the pass hasn't run on f3 yet.
+; CHECK: IR Dump After InferAddressSpacesPass on f3
----------------
arsenm wrote:

can you reproduce by adding optnone to f3 instead of relying on debug printing?

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


More information about the llvm-commits mailing list