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] Improve when TRUTH_AND_EXPR is created from TRUTH_ANDIF_EXPR


This patch improves when fold creates an TRUTH_AND_EXPR for an TRUTH_ANDIF_EXPR
(likewise for TRUTH_ORIF_EXPR to TRUTH_OR_EXPR) for decls as the operands.
This patch makes the following functions to produce the same asm on x86:


void g(void);
void h(void);
void f(int i, int j)
{
  bool a = i == 2;
  bool b = j == 3;
  if (a && b)
    g();
  else
    h();
}
void f1(int i, int j)
{
  if (i == 2 && j == 3)
    g();
  else
    h();
}

This happens more in C++ than C because of more use inline functions in C++.
This was pointed out to me by Richard Guenther in IRC and I decided to look into it.


OK? Bootstrapped and tested on both powerpc-darwin and i686-pc-linux-gnu with
no regressions.


Thanks,
Andrew Pinski

ChangeLog:

	* fold-const.c (fold_truthop): Simplify LHS ANDIF_EXPR RHS for simple
	RHS and LHS.

Attachment: t1.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]