Skip to content

[Attributor] Fix an issue that an access is skipped by mistake #101862

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

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

shiltian
Copy link
Contributor

@shiltian shiltian commented Aug 4, 2024

When we check if an access can be skipped, there is a case that an
inter-procedural interference access exists after a dominant write. Currently we
rely on AAInterFnReachability to tell if the access can be reachable. If it is
not, we can safely skip the access. However, it is based on an assumption that
the AA exists. It is possible that the AA doesn't exist. In this case, we can't
safely assume the acess can be skipped because we have to assume the access can
reach. This can happen when AAInterFnReachability is not in the allowed AA
list when creating the attributor, such as AMDGPUAttributor.

@shiltian shiltian marked this pull request as ready for review August 4, 2024 03:40
Copy link
Contributor Author

shiltian commented Aug 4, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @shiltian and the rest of your teammates on Graphite Graphite

@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2024

@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-llvm-transforms

Author: Shilei Tian (shiltian)

Changes

When we check if an access can be skipped, there is a case that an
inter-procedural interference access exists after a dominant write. Currently we
rely on AAInterFnReachability to tell if the access can be reachable. If it is
not, we can safely skip the access. However, it is based on an assumption that
the AA exists. It is possible that the AA doesn't exist. In this case, we can't
safely assume the acess can be skipped because we have to assume the access can
reach. This can happen when AAInterFnReachability is not in the allowed AA
list when creating the attributor, such as AMDGPUAttributor.


Full diff: https://github.com/llvm/llvm-project/pull/101862.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+1-1)
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index cd31c4be1c1da..1a551faec6dff 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1331,7 +1331,7 @@ struct AAPointerInfoImpl
         // itself either.
         bool Inserted = ExclusionSet.insert(&I).second;
 
-        if (!FnReachabilityAA ||
+        if (FnReachabilityAA &&
             !FnReachabilityAA->instructionCanReach(
                 A, *LeastDominatingWriteInst,
                 *Acc.getRemoteInst()->getFunction(), &ExclusionSet))

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testcase?

@shiltian
Copy link
Contributor Author

shiltian commented Aug 4, 2024

Testcase?

Well, the thing is, this can only be exposed in an Attributor use that doesn't have AAInterFnReachability. Regular AttributorPass will not have this issue. Only AMDGPUAttributorPass can do this, but the enabling of AAIndirectCallInfo has been reverted so even that can't expose it.

What I can do I guess is still to include the test case in this PR and the enabling of AAIndirectCallInfo in AMDGPUAttributor should not break it. Is that okay?

@shiltian shiltian force-pushed the users/shiltian/dont-skip-if-no-aa branch from 70d02a3 to 8c53a8b Compare August 4, 2024 14:41
@shiltian
Copy link
Contributor Author

shiltian commented Aug 5, 2024

ping

@arsenm
Copy link
Contributor

arsenm commented Aug 5, 2024

Testcase?

Well, the thing is, this can only be exposed in an Attributor use that doesn't have AAInterFnReachability. Regular AttributorPass will not have this issue. Only AMDGPUAttributorPass can do this, but the enabling of AAIndirectCallInfo has been reverted so even that can't expose it.

What I can do I guess is still to include the test case in this PR and the enabling of AAIndirectCallInfo in AMDGPUAttributor should not break it. Is that okay?

Pre-commit the test that would break in the next patch in its working state?

@shiltian
Copy link
Contributor Author

shiltian commented Aug 5, 2024

Testcase?

Well, the thing is, this can only be exposed in an Attributor use that doesn't have AAInterFnReachability. Regular AttributorPass will not have this issue. Only AMDGPUAttributorPass can do this, but the enabling of AAIndirectCallInfo has been reverted so even that can't expose it.
What I can do I guess is still to include the test case in this PR and the enabling of AAIndirectCallInfo in AMDGPUAttributor should not break it. Is that okay?

Pre-commit the test that would break in the next patch in its working state?

Hmm, I didn't follow.

@rovka
Copy link
Collaborator

rovka commented Aug 6, 2024

Testcase?

Well, the thing is, this can only be exposed in an Attributor use that doesn't have AAInterFnReachability. Regular AttributorPass will not have this issue. Only AMDGPUAttributorPass can do this, but the enabling of AAIndirectCallInfo has been reverted so even that can't expose it.

I'm not very familiar with these APIs, but is this something that would be easier to test with a C++ unit test? I see there are already some attributor unit tests.

@shiltian
Copy link
Contributor Author

shiltian commented Aug 6, 2024

Testcase?

Well, the thing is, this can only be exposed in an Attributor use that doesn't have AAInterFnReachability. Regular AttributorPass will not have this issue. Only AMDGPUAttributorPass can do this, but the enabling of AAIndirectCallInfo has been reverted so even that can't expose it.

I'm not very familiar with these APIs, but is this something that would be easier to test with a C++ unit test? I see there are already some attributor unit tests.

Yes, that's a good point. However, this issue requires a target where a stack variable is not accessible by other threads (effectively a GPU). I can't add target triple in the unit test because it will break a build if the target is not enabled.

@shiltian shiltian force-pushed the users/shiltian/dont-skip-if-no-aa branch from 8c53a8b to 0dd6941 Compare August 6, 2024 20:21
The tests kept being based on std::string instead of std::string_view to
allow testing with older C++ dialects.

Adds tests for:
- LWG3112 system_error and filesystem_error constructors taking a string
may not be able to meet their postconditions
@shiltian shiltian force-pushed the users/shiltian/dont-skip-if-no-aa branch from 0dd6941 to fdc014a Compare August 6, 2024 20:22
@shiltian shiltian merged commit 53d33d3 into main Aug 7, 2024
7 checks passed
@shiltian shiltian deleted the users/shiltian/dont-skip-if-no-aa branch August 7, 2024 01:29
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 7, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building llvm at step 10 "Add check check-offload".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/3243

Here is the relevant piece of the build log for the reference:

Step 10 (Add check check-offload) failure: test (failure)
******************** TEST 'libomptarget :: amdgcn-amd-amdhsa :: offloading/schedule.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp    -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib  -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/schedule.c.tmp /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a && /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/schedule.c.tmp 2>&1 | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c
# executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/schedule.c.tmp /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/schedule.c.tmp
# executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c
# .---command stderr------------
# | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c:80:12: error: CHECK: expected string not found in input
# |  // CHECK: test no order OK
# |            ^
# | <stdin>:1:1: note: scanning from here
# | Fail to schedule in order.
# | ^
# | <stdin>:2:1: note: possible intended match here
# | test ordered OK
# | ^
# | 
# | Input file: <stdin>
# | Check file: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/offloading/schedule.c
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             1: Fail to schedule in order. 
# | check:80'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
# |             2: test ordered OK 
# | check:80'0     ~~~~~~~~~~~~~~~~
# | check:80'1     ?                possible intended match
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

********************


@shiltian
Copy link
Contributor Author

shiltian commented Aug 7, 2024

Hmm, I can't reproduce this issue on gfx1030 as well as gfx90a.

@jdoerfert
Copy link
Member

Hmm, I can't reproduce this issue on gfx1030 as well as gfx90a.

Was a fluke: https://lab.llvm.org/buildbot/#/builders/73/builds/3244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants