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: [RFC][PR target/39726 P4 regression] match.pd pattern to do type narrowing


On Fri, 30 Jan 2015, Jeff Law wrote:

> +/* If we are testing a single bit resulting from a binary
> +   operation in precision P1 where the operands were widened
> +   precision P2 and the tested bit is the sign bit for
> +   precision P2.  Rewrite so the binary operation is in
> +   precision P2.  */

To avoid introducing undefined behavior, if the operation is arithmetic 
rather than bitwise and the original type with precision P2 is signed then 
you need to convert the operands to the corresponding unsigned type.

(I'm not sure how you avoid needing to convert the final result back to 
the original type of the expression to avoid type mismatches in the 
containing expression, but such a conversion back to the original type 
would need to be a zero-extension not a sign-extension and so for that I'd 
suppose the inner type should be unsigned even for bitwise operations.

-- 
Joseph S. Myers
joseph@codesourcery.com


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