This is the mail archive of the 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: [PATCH, i386]: Rewrite x87 sqrt patterns, take 2a (macroized)

Roger Sayle wrote:

Hi Uros,

On Fri, 24 Nov 2006, Uros Bizjak wrote:

2006-11-24 Uros Bizjak <>

	config/i386/ (UNSPEC_TRUNC_NOOP): New unspec definition.
	(X87MODEF): New mode macro.
	(ssemodefsuffix): New mode attribute.
	(truncxf<mode>2_i387_noop_unspec): New insn pattern.
	(sqrt_extend<mode>xf2_i387): New insn pattern.
	(sqrt<mode>2): For non-SSE sqrt, emit sqrt_extend<mode>xf2_i387
	insn and truncate result back to original mode using
	UNSPEC_TRUNC_NOOP truncation.
	(*sqrt<mode>2_sse): Implement using SSEMODEF mode macro and
	ssemodefsuffix mode attribute.
	(*sqrtsf2_mixed, *sqrtsf2_i387, *sqrtdf2_mixed, *sqrtdf2_i387)
	(*sqrtextendsfdf2_i387, *sqrtextendsfxf2_i387)
	(*sqrtextenddfxf2_i387): Remove insn patterns.

	(fmodsf3, fmoddf3, remaindersf3, remainderdf3): Use noop
	truncation patterns.

reg-stack.c (get_true_reg): Handle UNSPEC_TRUNC_NOOP.

This patch looks like a step in the right direction. Ok for mainline.

However my brain isn't working at the moment, so I'm unsure whether and
how the UNSPEC_TRUNC_NOOP gets optimized away with -ffast-math. For

This part of reg-stack.c change to get_true_reg() lowers UNSPEC_TRUNC_NOOP to plain move:

+      case UNSPEC:
+       if (XINT (*pat, 1) == UNSPEC_TRUNC_NOOP)
+         {
+           pat = & XVECEXP (*pat, 0, 0);
+           break;
+         }

When operands[0] == operands[1], the move itself is removed, and at this point the optimization you described below takes place.
(During the discussion, it was agreed that builtins can extend returned value to XFmode without truncating the value back to its original mode, as the user can use -ffloat store in this case or -fno-builtin-XX).

example, i386.c's output_387_reg_move doesn't appear to do anything
clever when operands[0] == operands[1]. However even without
understanding exactly what's going on, I agree with the philosophy
of making the XFmode operations more explicit and using macros to
simplify the backends patterns, and I trust you enough that your
implementation is sound. I can figure out how things work once its
in the tree.

Roger, thanks for your review!

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