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]

[RFC] small compile time improvement on PPC (PR 10588)


I noticed that on PPC GCC was outputting some serializing instructions
for simple things like a==0||b==0 (which shows up a lot in GCC) so I
decided to have it be outputted (clz(a)|clz(b))>>5 (5 is really
log2(clz(0))) which speeds up GCC compile time about 3%.  This is an
RFC only because there are no comments in the code and the name of
the target macro name, USE_CLZ_FOR_EQUAL_TO_ZERO_OR, to turn this on
is really not named well.

If someone knows of a better way of doing this and maybe a better name
for the macro that would be very helpful.

Bootstrapped on powerpc-apple-darwin with this enabled with no regressions.

Thanks,
Andrew Pinski

ChangeLog:
	* expr.c (expand_expr_real_1) <case BIT_IOR_EXPR/TRUTH_OR_EXPR>:
	Expand a==0||b==0 as (clz(a)|clz(b))>>(log2(clz(0))).

Patch:
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.647
diff -u -p -r1.647 expr.c
--- expr.c	19 May 2004 06:26:21 -0000	1.647
+++ expr.c	28 May 2004 13:22:49 -0000
@@ -8269,6 +8269,38 @@ expand_expr_real_1 (tree exp, rtx target

case TRUTH_OR_EXPR:
case BIT_IOR_EXPR:
+ if (USE_CLZ_FOR_EQUAL_TO_ZERO_OR && optimize
+ && TREE_CODE (TREE_OPERAND(exp, 0)) == EQ_EXPR
+ && TREE_CODE (TREE_OPERAND(exp, 1)) == EQ_EXPR
+ && integer_zerop (TREE_OPERAND (TREE_OPERAND(exp, 0), 1))
+ && integer_zerop (TREE_OPERAND (TREE_OPERAND(exp, 1), 1)))
+ {
+ tree expr0 = TREE_OPERAND (TREE_OPERAND(exp, 0), 0);
+ tree expr1 = TREE_OPERAND (TREE_OPERAND(exp, 1), 0);
+ enum machine_mode op0_mode = promote_mode (TREE_TYPE (expr0),
+ TYPE_MODE (TREE_TYPE (expr0)),
+ &unsignedp, 0);
+ enum machine_mode op1_mode = promote_mode (TREE_TYPE (expr1),
+ TYPE_MODE (TREE_TYPE (expr1)),
+ &unsignedp, 0);
+ if (op0_mode == op1_mode
+ && clz_optab->handlers[op1_mode].insn_code
+ != CODE_FOR_nothing)
+ {
+ mode = op0_mode;
+ op0 = expand_expr (expr0, NULL_RTX, VOIDmode, 0);
+ op1 = expand_expr (expr1, NULL_RTX, VOIDmode, 0);
+ op0 = expand_unop (mode, clz_optab, op0, NULL_RTX, 1);
+ op1 = expand_unop (mode, clz_optab, op1, NULL_RTX, 1);
+ temp = expand_binop (GET_MODE (op0), ior_optab, op0, op1, NULL_RTX,
+ 0, OPTAB_LIB_WIDEN);
+
+ return expand_shift (RSHIFT_EXPR, GET_MODE(temp), temp,
+ build_int_2 (exact_log2 (GET_MODE_BITSIZE (mode)), 0),
+ subtarget, 1);
+ }
+ }
+
this_optab = ior_optab;
goto binop;



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