What is the value of undef * 0 in LLVM? According to its definition in the LLVM IR reference; "The string ‘undef‘ can be used anywhere a constant is expected..." Am I correct to say that undef * 0 = 0 following this definition? Best Regards, soham
On 2016-09-02 14:33, Soham Chakraborty via llvm-dev wrote:> What is the value of undef * 0 in LLVM? > > According to its definition in the LLVM IR reference; > > "The string ‘undef‘ can be used anywhere a constant is expected..." > > Am I correct to say that undef * 0 = 0 following this definition?Yes, this is correct. The optimizer can insert any value for 'undef', so this transformation is correct for multiple reasons. (a) X * 0 = 0 is correct for any X because of arithmethic rules, so you don't even need 'undef' for X. (b) undef * X = 0 is correct as well by choosing 0 for undef. Your example is a special case of this by setting X = 0. -Manuel> Best Regards, > soham > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
llvm thinks so. You can easily see what it actually does in cases like this. echo 'int foo(int a){return 23 * a;}' >undeftimes.c clang -S -emit-llvm undeftimes.c vi undeftimes.ll # change the 23 to undef llc undeftimes.ll less undeftimes.s Personally, I find ARM (or other RISC) code far easier to follow than x86, so I generally add a "-march=arm" to the llc step if I'm on an x86 host, but that's personal preference. foo: push {r0} mov r0, #0 add sp, sp, #4 mov pc, lr Yep .. it just returns 0. 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) On Fri, Sep 2, 2016 at 3:33 PM, Soham Chakraborty via llvm-dev < llvm-dev at lists.llvm.org> wrote:> What is the value of undef * 0 in LLVM? > > According to its definition in the LLVM IR reference; > > "The string ‘undef‘ can be used anywhere a constant is expected..." > > Am I correct to say that undef * 0 = 0 following this definition? > > Best Regards, > soham > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160902/e72ede19/attachment.html>
On 2016-09-02 14:59, Bruce Hoult via llvm-dev wrote:> llvm thinks so. > > You can easily see what it actually does in cases like this. > > echo 'int foo(int a){return 23 * a;}' >undeftimes.c > clang -S -emit-llvm undeftimes.c > vi undeftimes.ll # change the 23 to undef > llc undeftimes.ll > less undeftimes.s > > Personally, I find ARM (or other RISC) code far easier to follow than > x86, > so I generally add a "-march=arm" to the llc step if I'm on an x86 > host, > but that's personal preference.Or even `opt -S -O3 undeftimes.ll` to see what the (full) optimizer pipeline does instead of just what llc does (llc only does a limited set of transformations).> foo: > push {r0} > mov r0, #0 > add sp, sp, #4 > mov pc, lr > > Yep .. it just returns 0. > > 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) > > On Fri, Sep 2, 2016 at 3:33 PM, Soham Chakraborty via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> What is the value of undef * 0 in LLVM? >> >> According to its definition in the LLVM IR reference; >> >> "The string ‘undef‘ can be used anywhere a constant is expected..." >> >> Am I correct to say that undef * 0 = 0 following this definition? >> >> Best Regards, >> soham >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
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) > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160902/8bfd8450/attachment.html>