[llvm] [CorrelatedValuePropagation] Run CVP before first SimplifyCFG (PR #141125)

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 17:44:20 PDT 2025


fmayer wrote:

> For the motivating case, the context-sensitive range analysis is blocked by the `isGuaranteedNotToBeUndef` check:

This gave me the idea to propagate `undef` from the `Cond` to the `TrueVal` and `FalseVal`: https://github.com/llvm/llvm-project/commit/d660f732e19bc213b2c3a4ae6581799d79f77aaa

It seems like a correct thing to do intuitively to me. https://llvm.org/docs/UndefinedBehavior.html says "An undef value represents any value of a given type. Moreover, each use of an instruction that depends on undef can observe a different value. " on the result seems like a way to encode  "// If the value is undef, a different value may be chosen in the select condition." from the code block you quoted.

I don't have enough experience with LVI to understand the full implications of this. The tests still pass (and fail if I just remove the `isGuaranteedNotToBeUndef` condition completely), and my motivating example optimizes as it should (and prints the correct range `constantrange incl. undef <1, 13>` with `-debug-only=lazy-value-info`). Any thoughts? I hope this makes sense, if it doesn't sorry and thanks for bearing with me in advance.

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


More information about the llvm-commits mailing list