This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Move some bit and binary optimizations in simplify and match


On Wed, 14 Oct 2015, Richard Biener wrote:

On Wed, Oct 14, 2015 at 12:45 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
On Wed, 14 Oct 2015, Richard Biener wrote:

+/* Fold (a * (1 << b)) into (a << b)  */
+(simplify
+ (mult:c @0 (convert? (lshift integer_onep@1 @2)))
+  (if (! FLOAT_TYPE_P (type)
+        && tree_nop_conversion_p (type, TREE_TYPE (@2)))
+   (lshift @0 (convert @2))))

You don't need/want to convert @2 (fold-const doesn't convert, does it?),
and you don't need to check for tree_nop_conversion_p.


I think for long x and x * (long)(1u << b) you need to do because the
result for b == 33 would be different.


- that check should be with TREE_TYPE (@1)

of course

- 1u << 33 is undefined, isn't it?

Is it?  I thought it were fine for unsigned.

Can't be, Intel thinks it is 2u while some other hardware thinks it is 0.

Not sure if we should exploit this
undefinedness here.  Btw, if it were a truncating conversion then the
resulting shift could be invalid if @2 is too big (but not too big for the
wider shift).

Yes, that was my example below.

So either way I think we should only allow nop conversions
here (as fold-const.c did).

I agree that's the safest / easiest for now.

x * (int)(1ul << b), which for b=33 should yield 0, would give the undefined
x << b so some check does seem needed indeed.

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]