This is a rebase of D85604 by Nicolai Haehnle <nicolai.haehnle@amd.com>. The
other changes in the original review have already been committed at different
points in time.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Shouldn't this be covered by the speculatable attribute? A convergent function shouldn't be marked speculatable.
It depends. In the future we could contextually speculate convergent instructions (e.g. if the conditions reaching the point are uniform)
I still think that would not allow you to put speculatable on the function. A speculatable function has to be speculatable unconditionally. Absense of the speculatable attribute does not imply that the call cannot be speculated, just that we don't know that it is always safe to speculate.
From a single-threaded point of view, a speculatable function is speculatable unconditionally, because the attribute is only reporting that certain side-effects will not happen. But whether it can be speculated across a divergent branch is decided by whether it is marked convergent. These two things are orthogonal. If a pass wants to speculate a convergent function across a uniform branch (or later even across a divergent branch if permitted by convergence tokesn), then this check for isConvergent will be combined by additional information passed from outside to isSafeToSpeculativelyExecute().
Theoretically, it is plausible that some function may be non-convergent and speculatable, but based on the environment (e.g., HIP or Vulcan or OpenCL), a call to such a function may be convergent. I don't actually have an example of such a thing right now, though it was considered at one point.
Abandoning. I agree with relying on attribute speculatable. If we figure out the conditions that make a convergent call speculatable, then at that time, we should use the appropriate attribute to record that fact. On the other hand, if speculation of a convergent call is dependent on the surrounding control flow, then we will probably have to do it as a separate optimization.
llvm/lib/Analysis/ValueTracking.cpp | ||
---|---|---|
6006–6012 | Just below, all the other "call-like" instructions are simply assumed to be not safe for speculation. |
Should go through the CallBase rather than separately checking the callee and call site attributes. Also you're missing invokes