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]

[PATCH] Fix a type mismatch in fold-const


While looking into PR 21082 with Richard Guenther, we found a type mismatch
by fold converting "(long)((unsigned)(a) * 4) - (long)((unsigned)(b) * 4)"
into: ((unsigned int) a - (unsigned int) b) * 4 without removing the casts and the
MINUS_EXPR have a different type than its operands.


The following is not optimized on the tree level because of the mismatched
types:
/* { dg-options "-O2 -fdump-tree-optimized" */
long a, b;
void link_error();
void f()
{
if ((long)((unsigned)(a) * 4) - (long)((unsigned)(b) * 4) != (a- b)*4)
link_error();
}


/* There should no longer be any reference to link_error */
/* { dg-final { scan-tree-dump-times "link_error " 0 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

OK? Bootstrapped and tested on ppc-darwin with no regressions.

Thanks,
Andrew Pinski

ChangeLog:

	* fold-const.c (fold_binary): Convert the new operands for the
	"(A * C) - (B * C) -> (A-B) * C" conversion.
	Likewise for the "(A * C1) - (A * C2) -> A * (C1-C2)" conversion.


Attachment: fixtype.diff.txt
Description: Text document


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