Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -930,6 +930,11 @@ if (EdgesMissing) continue; + // If this is an identity arc, we cannot be less specific now than we were + // before. + if (PhiVal == PN) + EdgeResult = intersect(EdgeResult, Result); + Result.mergeIn(EdgeResult, DL); // If we hit overdefined, exit early. The BlockVals entry is already set Index: test/Transforms/CorrelatedValuePropagation/identity.ll =================================================================== --- /dev/null +++ test/Transforms/CorrelatedValuePropagation/identity.ll @@ -0,0 +1,30 @@ +; RUN: opt -S < %s -correlated-propagation | FileCheck %s + +; CHECK-LABEL: @f +; CHECK: ret i32 3 +define i32 @f(i32 %n) { +entry: + br label %while.cond + +while.cond: + %i = phi i32 [ 2, %entry ], [ %i, %one ], [ 3, %two ] + %cmp = icmp slt i32 %i, 3 + br i1 %cmp, label %while.body, label %return + +while.body: + %call = call i32 @g(i32 1) + %add = add i32 %i, 6 + %cmp3 = icmp sgt i32 %add , 6 + br i1 %cmp3, label %one, label %two + +one: + br label %while.cond + +two: + br label %while.cond + +return: + ret i32 %i +} + +declare i32 @g(i32)