Skip to content

[AMDGPU] invalid PHI node generated after AMDGPULowerModuleLDS Pass #167500

@hzwangchaochen

Description

@hzwangchaochen

The simplified LLVM IR is as follows:

@lds.size.2.align.2 = internal unnamed_addr addrspace(3) global [6144 x half] poison, align 2
define dso_local amdgpu_kernel void @flash_attentionV1(ptr addrspace(1) %out) {
bb3:
  switch i32 0, label %bb10 [
    i32 18, label %bb7
    i32 1, label %bb7
    i32 0, label %bb10
  ]
bb5:
  switch i32 0, label %bb10 [
    i32 18, label %bb7
    i32 1, label %bb7
    i32 0, label %bb10
  ]

bb7:                                              ; preds = %bb5, %bb5, %bb3, %bb3
  %phi8 = phi i64 [ ptrtoint (ptr addrspacecast (ptr addrspace(3) @lds.size.2.align.2 to ptr) to i64), %bb5 ], [ ptrtoint (ptr addrspacecast (ptr addrspace(3) @lds.size.2.align.2 to ptr) to i64), %bb5 ], [10, %bb3], [10, %bb3]
  store i64 %phi8, ptr addrspace(1) %out, align 8
  br label %bb10

bb10:                                             ; preds = %bb3, %bb3, %bb2
  ret void
}

编译命令如下:

./build/bin/llc -mtriple=amdgcn xxx.ll or ./build/bin/opt -S -mtriple=amdgcn-- -amdgpu-lower-module-ld xxx.ll

After AMDGPULowerModuleLDS Pass
bb5 and bb7 are transformed as follows:

bb5:                                              ; No predecessors!
  %0 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.flash_attentionV1.lds to ptr
  %1 = ptrtoint ptr %0 to i64
  %2 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.flash_attentionV1.lds to ptr
  %3 = ptrtoint ptr %2 to i64
  switch i32 0, label %bb10 [
    i32 18, label %bb7
    i32 1, label %bb7
    i32 0, label %bb10
  ]
bb7:                                              ; preds = %bb5, %bb5, %bb3, %bb3
  %phi8 = phi i64 [ %3, %bb5 ], [ %1, %bb5 ], [ 10, %bb3 ], [ 10, %bb3 ]
  store i64 %phi8, ptr addrspace(1) %out, align 8
  br label %bb10

Then we encountered the following error message:

PHI node has multiple entries for the same basic block with different incoming values!
  %phi8 = phi i64 [ %3, %bb5 ], [ %1, %bb5 ], [ 10, %bb3 ], [ 10, %bb3 ]
label %bb5
  %3 = ptrtoint ptr %2 to i64
  %1 = ptrtoint ptr %0 to i64
in function flash_attentionV1

Any ideas for this issues, thanks a lot~

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions