[llvm] [NewGVN] Prevent cyclic reference when building phiofops (PR #69418)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 18 01:58:28 PDT 2023
================
@@ -3812,9 +3812,20 @@ Value *NewGVN::findPHIOfOpsLeader(const Expression *E,
auto *MemberInst = dyn_cast<Instruction>(Member);
if (MemberInst == OrigInst)
continue;
+
// Anything that isn't an instruction is always available.
if (!MemberInst)
return Member;
+
+ // Prevent cyclic reference, such as:
+ // %a = add i64 %phi, 1
+ // %foundinst = add i64 %a, 1
+ // =>
+ // %phiofops = phi i64 [1, %BB1], [%foundinst, %BB2]
+ // %foundinst = add i64 %phiofops, 1
+ if (llvm::find(MemberInst->operands(), OrigInst) != MemberInst->op_end())
----------------
nikic wrote:
is_contained
https://github.com/llvm/llvm-project/pull/69418
More information about the llvm-commits
mailing list