The arm patch 161344 to transform TST into LSLS

Richard Earnshaw rearnsha@arm.com
Fri Jul 2 09:16:00 GMT 2010


On Fri, 2010-07-02 at 08:53 +0800, Carrot Wei wrote:
> Hi Richard
> 
> The new peephole2 and the old pattern does different optimization. As
> you have described the peephole2 can optimize the cases that test a
> single bit in a word. But the old pattern tests if the bit fields at
> the low end of a word is equal or not equal to zero, the bit field may
> contain more than 1 bit. Interestingly the test case with the old
> pattern can fit in both situations. If we change the test case as
> following, it can show the regression.
> 
> struct A
> {
>   int v:2;
> };
> 
> 
> int bar();
> int foo(struct A* p)
> {
>   if (p->v)
>     return 1;
>   return bar();
> }
> 
> So we need another peephole2 to bring that optimization back.
> 
> thanks
> Guozhi

Yes, a peep2 for that should be pretty straight-forward to generate.
Simply transform the code into a left-shift and compare with 0, then a
branch if eq/ne.  

R.



More information about the Gcc-patches mailing list