[llvm] [llvm] Don't combine repeated subnormal divisors (PR #149333)
Andy Kaylor via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 18 09:48:33 PDT 2025
andykaylor wrote:
> I also don't think arcp should give license to introduce new infinities; perhaps this also should require reassoc
This is a fundamental problem with mixing `arcp` with `ninf`. Any non-constant value could be a subnormal value whose reciprocal will be infinity. So we have to make a choice, either `arcp` gives implicit permission for a transformation that could potentially introduce an infinity where none existed previously or `arcp` only allows reciprocal math if the result can be proven not to be infinity. The latter would render the flag nearly useless.
> I don't think this should special case constant values. The problem still exists for the non-constant case
That was my initial reaction as well, but I've come around to what @ashermancinelli is trying to achieve here. If we say that `arcp` allows performing a reciprocal operation that could introduce infinity, then by using it you are accepting the risk of introducing a value that is dynamically poison, but the optimizer will never know that the value is poison, and so it won't optimize based on it being poison. You may still get incorrect results, but less arbitrarily so. In the constant case, however, we know that the transformation is introducing a poison value (if the `ninf` flag is set on any of the operations involved), so even if it is permitted by the semantics of the IR for the optimizer to do so, we should avoid it.
If we take the alternative approach and say that we should not perform this operation in any case where it might introduce an infinity, we need to remove the optimization entirely. The same would be true of almost any arcp-based transformation.
https://github.com/llvm/llvm-project/pull/149333
More information about the llvm-commits
mailing list