[PATCH][GCC] Simplification of 1U << (31 - x)

Sudi Das Sudi.Das@arm.com
Wed Apr 12 09:30:00 GMT 2017


Hi all

This is a fix for PR 80131 
Currently the code A << (B - C) is not simplified.
However at least a more specific case of 1U << (C -x) where C = precision(type) - 1 can be simplified to (1 << C) >> x.

This is done by adding a new simplification rule in match.pd

So for a test case :

unsigned int f1(unsigned int i)
{
  return 1U << (31 - i);
}

We see a gimple dump of 

f1 (unsigned int i)
{
  unsigned int D.3121;

  D.3121 = 2147483648 >> i;
  return D.3121;
}

instead of 

f1 (unsigned int i)
{
  unsigned int D.3121;

  _1 = 31 - i;
  D.3121 = 1 << _1;
  return D.3121;
}


Add a new test case and checked for regressions on bootstrapped aarch64-none-linux-gnu.
Ok for stage 1?

Thanks
Sudi

2017-03-23  Sudakshina Das  <sudi.das@arm.com>

	PR middle-end/80131
	* match.pd: Simplify 1 << (C - x) where C = precision (type) - 1.

2017-03-23  Sudakshina Das  <sudi.das@arm.com>

	PR middle-end/80131
	* testsuite/gcc.dg/pr80131-1.c: New Test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-7259-4(1).diff
Type: text/x-patch
Size: 1815 bytes
Desc: patch-7259-4(1).diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170412/78a0c2fa/attachment.bin>


More information about the Gcc-patches mailing list