[llvm-dev] undef * 0

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 12 22:31:57 PDT 2016

Hi Soham,

You're right that in LLVM IR arithmetic (with the current definition
of `undef`) is not distributive.  You can't replace `A * (B + C)` with
`A * B + A * C` in general, since (exactly as you said) for A =
`undef`, B = `1`, C = `-1` the former always computes `0` while the
latter computes `undef`.  This is fundamentally because replacing `A *
(B + C)` with `A * B + A * C` increases the number of uses of `A`
(which is `undef`), and thus injects more behavior into the program.
I _think_ going from `A * B + A * C` to `A * (B + C)` is okay though.

Here is a simpler example of a similar issue: `X - X` is not
equivalent `0`, in that `0` cannot be replaced with `X - X`, even
though `X - X` can be folded to `0`.

-- Sanjoy

More information about the llvm-dev mailing list