[llvm-dev] undef * 0

Soham Chakraborty via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 12 01:36:09 PDT 2016


Hi,

Back to the original question - undef * 0 = 0 may have some issues.

Consider the evaluation of the expression undef * (1 - 1)

(1) undef * (1 - 1) ~> undef * 0 ~> 0 (as suggested)

(2) undef * (1 - 1) ~> undef * 1 + undef * (-1) ~> undef + undef ~> undef
and now the evaluation of undef can be some other value than 0.

Thus it does not follow the law of distribution of multiplication over
addition property and the algebraic transformations are ambiguous.

Similarly associativity of boolean algebra is also violated as follows:

undef & a & !a
(1) ~> (undef & a) & !a ~> undef & !a ~> undef
(2) ~> undef (a & !a) ~> undef & 0 ~> 0

Is there any clear set of rules how LLVM handles such cases?

Best Regards,
soham


> I don't know of a way to do it from the command-line, but if you're
> willing
> to change the IR, you can add the optsize (for -Os) or minsize (for -Oz)
> IR
> attribute to the function you're compiling.
>
> On Fri, Sep 2, 2016 at 5:59 AM, Bruce Hoult via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Idle question, if anyone is reading still ... how do you get llc to do
>> -Os
>> or -Oz? The docs say the argument must be an integer, and anything other
>> than 0..3 is rejected. (in fact .. bug report ... 10 thru 39 are also
>> silently accepted as are 100 thru 399 etc)
>>
>>
>



More information about the llvm-dev mailing list