`IntrConvergent` was originally added to `dx.resource.getpointer` to prevent optimization passes (`SimplifyCFG`, `GVN`) from sinking the intrinsic out of control flow branches, which would create phi nodes on the returned pointer. Using `IntrInaccessibleMemOnly` and `IntrReadMem` semantics still prevent passes from merging or sinking identical calls across branches. However, this allows the call to be moved within a single control flow path. Updates relevant tests and adds a new test to demonstrate a now legal potential optimization. This was discovered when https://github.com/llvm/llvm-project/pull/188792 caused the following failure: https://github.com/llvm/llvm-project/actions/runs/24577221310/job/71865579618. When emitting convergence control tokens, each resource access is then a user of the convergence control tokens, which makes it's use more unnecessarily restrictive for optimizations and in this case would prevent a loop unroll from taking place. Assisted by: Claude Opus 4.6
32 lines
1.4 KiB
LLVM
32 lines
1.4 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
|
|
; RUN: opt -passes=sink -S %s | FileCheck %s
|
|
|
|
; Verify that dx.resource.getpointer can be sunk into a branch where it is
|
|
; only used.
|
|
|
|
define void @can_sink_into_branch(i1 %cond) {
|
|
; CHECK-LABEL: define void @can_sink_into_branch(
|
|
; CHECK-SAME: i1 [[COND:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*:]]
|
|
; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_END:.*]]
|
|
; CHECK: [[IF_THEN]]:
|
|
; CHECK-NEXT: [[BUF:%.*]] = call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i32_1_0t(i32 0, i32 0, i32 1, i32 0, ptr null)
|
|
; CHECK-NEXT: [[PTR:%.*]] = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_i32_1_0t.i32(target("dx.RawBuffer", i32, 1, 0) [[BUF]], i32 0)
|
|
; CHECK-NEXT: store i32 42, ptr [[PTR]], align 4
|
|
; CHECK-NEXT: br label %[[IF_END]]
|
|
; CHECK: [[IF_END]]:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
entry:
|
|
%buf = call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i32_1_0t(i32 0, i32 0, i32 1, i32 0, ptr null)
|
|
%ptr = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_i32_1_0t.i32(target("dx.RawBuffer", i32, 1, 0) %buf, i32 0)
|
|
br i1 %cond, label %if.then, label %if.end
|
|
|
|
if.then:
|
|
store i32 42, ptr %ptr, align 4
|
|
br label %if.end
|
|
|
|
if.end:
|
|
ret void
|
|
}
|