diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp index bb7dbc2980f59..e05625344ee29 100644 --- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp @@ -997,7 +997,8 @@ void StructurizeCFG::simplifyHoistedPhis() { continue; OtherPhi->setIncomingValue(PoisonValBBIdx, V); - Phi->setIncomingValue(i, OtherV); + if (DT->dominates(OtherV, Phi)) + Phi->setIncomingValue(i, OtherV); } } } diff --git a/llvm/test/CodeGen/AMDGPU/structurize-hoist.ll b/llvm/test/CodeGen/AMDGPU/structurize-hoist.ll index 8b6e5eb8e6975..b4036517cc0d5 100644 --- a/llvm/test/CodeGen/AMDGPU/structurize-hoist.ll +++ b/llvm/test/CodeGen/AMDGPU/structurize-hoist.ll @@ -189,12 +189,11 @@ define void @test_nested_if(ptr %ptr, i32 %val, i1 %cond) { ; GFX900-NEXT: s_mov_b64 s[10:11], -1 ; GFX900-NEXT: s_xor_b64 s[4:5], s[6:7], -1 ; GFX900-NEXT: s_mov_b64 s[12:13], s[6:7] -; GFX900-NEXT: ; implicit-def: $vgpr3 +; GFX900-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) +; GFX900-NEXT: v_mov_b32_e32 v3, v4 ; GFX900-NEXT: s_and_saveexec_b64 s[8:9], s[4:5] ; GFX900-NEXT: s_cbranch_execz .LBB3_4 ; GFX900-NEXT: ; %bb.1: ; %if -; GFX900-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) -; GFX900-NEXT: v_mov_b32_e32 v3, v4 ; GFX900-NEXT: s_and_saveexec_b64 s[12:13], s[4:5] ; GFX900-NEXT: s_cbranch_execz .LBB3_3 ; GFX900-NEXT: ; %bb.2: ; %if_2 @@ -230,7 +229,6 @@ define void @test_nested_if(ptr %ptr, i32 %val, i1 %cond) { ; GFX900-NEXT: s_or_b64 exec, exec, s[8:9] ; GFX900-NEXT: s_and_saveexec_b64 s[6:7], s[4:5] ; GFX900-NEXT: s_or_b64 exec, exec, s[6:7] -; GFX900-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) ; GFX900-NEXT: flat_store_dword v[0:1], v4 ; GFX900-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) ; GFX900-NEXT: s_setpc_b64 s[30:31] diff --git a/llvm/test/Transforms/StructurizeCFG/hoist-zerocost.ll b/llvm/test/Transforms/StructurizeCFG/hoist-zerocost.ll index 71de4f45f154f..d084e199ceb89 100644 --- a/llvm/test/Transforms/StructurizeCFG/hoist-zerocost.ll +++ b/llvm/test/Transforms/StructurizeCFG/hoist-zerocost.ll @@ -172,7 +172,7 @@ define void @test_nested_if(ptr %ptr, i32 %val, i1 %cond) { ; CHECK-NEXT: [[A16:%.*]] = icmp slt i32 [[VAL]], 255 ; CHECK-NEXT: br i1 [[COND_INV]], label %[[THEN_2:.*]], label %[[FLOW1:.*]] ; CHECK: [[FLOW]]: -; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[TMP2:%.*]], %[[FLOW1]] ], [ poison, %[[ENTRY]] ] +; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[TMP2:%.*]], %[[FLOW1]] ], [ [[A_ELSE]], %[[ENTRY]] ] ; CHECK-NEXT: [[TMP1:%.*]] = phi i1 [ [[TMP3:%.*]], %[[FLOW1]] ], [ [[COND]], %[[ENTRY]] ] ; CHECK-NEXT: br i1 [[TMP1]], label %[[ELSE:.*]], label %[[MERGE:.*]] ; CHECK: [[THEN_2]]: