Is this a missed (simple) optimization?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
WP
Reply | Threaded
Open this post in threaded view
|

Is this a missed (simple) optimization?

WP
I think this is a missed optimization, but maybe I'm missing some significant piece of knowledge(!) as to why this might not be optimizable :)  Test case...
 
   int A;  // some global
   int B;  // some global

   void Test(int *Out)
   {
      *Out = A;   // Can't this be optimized away?
      *Out = B;
   };

The LLVM backend (tested 3.1 and 3.0 online demo) doesn't optimize away the first store, even with O3 level compiling in clang.  Is there some valid reason for this?

Any insight appreciated.  Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Is this a missed (simple) optimization?

Tim Northover-2
Hi,

If the function was called Test(&B) then the first store would affect
the second load.

Tim.

On Fri, Nov 16, 2012 at 11:58 AM, AnonW <[hidden email]> wrote:

> I think this is a missed optimization, but maybe I'm missing some significant
> piece of knowledge(!) as to why this might not be optimizable :)  Test
> case...
>
>    int A;  // some global
>    int B;  // some global
>
>    void Test(int *Out)
>    {
>       *Out = A;   // Can't this be optimized away?
>       *Out = B;
>    };
>
> The LLVM backend (tested 3.1 and 3.0 online demo) doesn't optimize away the
> first store, even with O3 level compiling in clang.  Is there some valid
> reason for this?
>
> Any insight appreciated.  Thanks.
>
>
>
> --
> View this message in context: http://llvm.1065342.n5.nabble.com/Is-this-a-missed-simple-optimization-tp51361.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
WP
Reply | Threaded
Open this post in threaded view
|

Re: Is this a missed (simple) optimization?

WP
Argh.... quite right!  I knew I was missing something obvious...

Many thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Is this a missed (simple) optimization?

Duncan Sands
In reply to this post by Tim Northover-2
> If the function was called Test(&B) then the first store would affect
> the second load.

You can use the "restrict" qualifier ("noalias" in LLVM) to tell the optimizers
that this kind of aliasing doesn't occur.

Ciao, Duncan.

>
> Tim.
>
> On Fri, Nov 16, 2012 at 11:58 AM, AnonW <[hidden email]> wrote:
>> I think this is a missed optimization, but maybe I'm missing some significant
>> piece of knowledge(!) as to why this might not be optimizable :)  Test
>> case...
>>
>>     int A;  // some global
>>     int B;  // some global
>>
>>     void Test(int *Out)
>>     {
>>        *Out = A;   // Can't this be optimized away?
>>        *Out = B;
>>     };
>>
>> The LLVM backend (tested 3.1 and 3.0 online demo) doesn't optimize away the
>> first store, even with O3 level compiling in clang.  Is there some valid
>> reason for this?
>>
>> Any insight appreciated.  Thanks.
>>
>>
>>
>> --
>> View this message in context: http://llvm.1065342.n5.nabble.com/Is-this-a-missed-simple-optimization-tp51361.html
>> Sent from the LLVM - Dev mailing list archive at Nabble.com.
>> _______________________________________________
>> LLVM Developers mailing list
>> [hidden email]         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev