Index: lib/Transforms/Scalar/NewGVN.cpp =================================================================== --- lib/Transforms/Scalar/NewGVN.cpp +++ lib/Transforms/Scalar/NewGVN.cpp @@ -2409,6 +2409,9 @@ moveValueToNewCongruenceClass(I, E, IClass, EClass); markPhiOfOpsChanged(E); } + // After moving I to the new class, its leader could have changed, which + // means that we might be able to simplify phi of ops involving it. + markPhiOfOpsChanged(createVariableOrConstant(I)); markUsersTouched(I); if (MemoryAccess *MA = getMemoryAccess(I)) Index: test/Transforms/NewGVN/pr35074-phi-of-ops-leader-change-after-moving-I.ll =================================================================== --- /dev/null +++ test/Transforms/NewGVN/pr35074-phi-of-ops-leader-change-after-moving-I.ll @@ -0,0 +1,36 @@ +; RUN: opt < %s -newgvn -S | FileCheck %s + +; CHECK-LABEL: for.cond: +; CHECK-NEXT: %phiofops = phi i32 [ 0, %entry ], [ %y.0, %for.inc6 ] +; CHECK-NEXT: %y.0 = phi i32 [ 1, %entry ], [ %inc7, %for.inc6 ] + +; CHECK-LABEL: for.body.lr.ph: +; CHECK-NEXT: %cmp = icmp ugt i32 %phiofops, %y.0 + +define void @test(i32 %this) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc6, %entry + %y.0 = phi i32 [ 1, %entry ], [ %inc7, %for.inc6 ] + br i1 undef, label %for.inc6, label %for.body.lr.ph + +for.body.lr.ph: ; preds = %for.cond + %sub = add nsw i32 %y.0, -1 + %cmp = icmp ugt i32 %sub, %y.0 + br i1 %cmp, label %for.end, label %for.body4.1 + +for.end: ; preds = %for.body4.1, %for.body.lr.ph + ret void + +for.inc6: ; preds = %for.cond + %inc7 = add nuw nsw i32 %y.0, 1 + br label %for.cond + +for.body4.1: ; preds = %for.body.lr.ph + %inc.1 = add nuw nsw i32 %y.0, 1 + tail call void @_blah(i32 %inc.1) + br label %for.end +} + +declare void @_blah(i32)