[llvm] [NewGVN] Prevent cyclic reference when building phiofops (PR #69418)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 05:11:15 PDT 2023
XChy wrote:
> For example, be an operand of one of the operands of the original instruction. Or an even more contrived case would be if one of the operands of the leader was the leader of one of the operands of the original instruction. I don't have any concrete examples of this happening and causing NewGVN to not terminate
For the first case, I think that's correct. I missed here. There is a case:
```llvm
define i64 @foo(i64 %e) {
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
%original = add i64 %indvars.iv, 1
%b = add i64 %original, 1
%c = sub i64 %b, 1
%phileader = add i64 %c, 1
%indvars.iv.next = add i64 %indvars.iv, 1
%tobool = icmp slt i64 %indvars.iv.next, 100
br i1 %tobool, label %for.body, label %end
end:
ret i64 %phileader
}```
But for the latter, I think that's OK. Based on my knowledge about this algorithm, if operand of `phiopsleader` is equivalent/congruent to the operand of `orig`. For example(May not so precise):
```llvm
declare void @use(i64)
define i64 @foo(i64 %operand_lead) {
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
%operand_mid = add i64 %operand_lead, 1
%operand = sub i64 %operand_lead, 1
%original = add i64 %indvars.iv, %operand
%phi_leader = add i64 %indvars.iv, %operand_lead
call void @use(i64 %original)
call void @use(i64 %phi_leader)
%indvars.iv.next = add i64 %indvars.iv, %operand
%tobool = icmp slt i64 %indvars.iv.next, 100
br i1 %tobool, label %for.body, label %end
end:
ret i64 0
}
```
It would be fine for me.
https://github.com/llvm/llvm-project/pull/69418
More information about the llvm-commits
mailing list