[llvm] [VPlan] Use InstSimplifyFolder in IRBuilder (PR #141225)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 08:18:29 PDT 2025


artagnon wrote:

> I am not sure if using InstSimplifyFolder is feasible, as during codegen the IR is in an incomplete state (phis may not have their incoming values set, branch destination may not be set, blocks with unreachable terminators). This is probably the reason for incorrect folds, as InstSimplify tries to derive information from incomplete IR and reaches incorrect conclusions.

Yeah, that's exactly the issue. I was just discussing with @nikic, and we could have a SimplifyQuery mode that disables analysis of phis, but I think InstSimplifyFolder is still a bit too expensive to use all the time. It does irk be a bit that InstSimplifyFolder is such a nice thing that exists, but has such niche use-cases.

> Doing folds at code-gen time not done intentionally at the moment, as it means we dont correctly consider them during cost modeling and VPlan execution should be as simple as possible (not complete yet but working towards that)

Although the cost-modeling argument makes sense, I'm not sure how we can prevent emitting things like `add x, 0` and `gep x, 0`, which were the opportunities found by this patch? Can you elaborate?

https://github.com/llvm/llvm-project/pull/141225


More information about the llvm-commits mailing list