Bug 29548 - Does not fold b * -2 + a * 6
Summary: Does not fold b * -2 + a * 6
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Richard Biener
URL:
Keywords: missed-optimization
Depends on:
Blocks: 23295
  Show dependency treegraph
 
Reported: 2006-10-22 15:56 UTC by Richard Biener
Modified: 2006-10-23 07:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-10-22 15:56:53


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-10-22 15:56:38 UTC
fold_plusminus_mult_expr does not fold

int f6 (int a, int b)
{
  return b * -2 + a * 6;
}

this blocks the fix for PR23295 because a fix for it makes the test for
PR23294 fail.
Comment 1 Richard Biener 2006-10-22 15:56:53 UTC
I have a patch.
Comment 2 Richard Biener 2006-10-23 07:19:49 UTC
Subject: Bug 29548

Author: rguenth
Date: Mon Oct 23 07:19:34 2006
New Revision: 117969

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117969
Log:
2006-10-24  Richard Guenther  <rguenther@suse.de>

	PR middle-end/27132
	PR middle-end/23295
	* builtins.c (fold_binary): Remove checks for flag_wrapv
	and flag_trapv where negate_expr_p covers these cases.

	* gcc.dg/pr27132.c: New testcase.
	* gcc.dg/pr23295.c: Likewise.
	* gcc.dg/tree-ssa/pr23294.c: Adjust patterns.
	* g++.dg/tree-ssa/pr19807.C: Likewise.

2006-10-23  Richard Guenther  <rguenther@suse.de>

	PR middle-end/29548
	* fold-const.c (fold_plusminus_mult_expr): Check exact power
	of two on the absolute value.
	(fold_binary): Fold x * -C to -x * C if x is easily negatable
	and negating -C does not overflow.

Added:
    trunk/gcc/testsuite/gcc.dg/pr23295.c
    trunk/gcc/testsuite/gcc.dg/pr27132.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/tree-ssa/pr19807.C
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr23294.c

Comment 3 Richard Biener 2006-10-23 07:20:56 UTC
Fixed.