This is the mail archive of the gcc@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]

Char shifts promoted to int. Why?


   Hi.

   I seem unable to get a QImode shift instruction from this code:

unsigned char x;

void qishifttest2 (unsigned int c)
{
	x <<= c;
}

   Already at the first tree dump, there's a promotion to int:

;; Function qishifttest2 (qishifttest2)
;; enabled by -tree-original

{
  x = (unsigned char) ((int) x << (int) c);
}

   The resulting code doesn't look good (i386):

qishifttest2:
	movzbl	x, %eax		# 23	*zero_extendqisi2_movzbw	[length = 7]
	movl	4(%esp), %ecx	# 21	*movsi_1/1	[length = 4]
	sall	%cl, %eax	# 9	*ashlsi3_1/1	[length = 2]
	movb	%al, x		# 10	*movqi_1/7	[length = 5]
	ret			# 26	return_internal	[length = 1]

   It should have shiftet x directly in memory:

	movl	4(%esp), %ecx
	salb	%cl, x
	ret

   Similarily for m68k,

qishifttest2:
	clr.l %d0		| 21	movsi_const0
	move.b x,%d0		| 22	*m68k.md:766
	move.l 4(%sp),%d1	| 20	*m68k.md:671/1
	lsl.l %d1,%d0		| 9	ashlsi3
	move.b %d0,x		| 10	*m68k.md:748/3
	rts

where

	move.l	4(%sp),	%d1
	lsl.b	%d1,	x
	rts

should have been generated. Also, notice the redundant zero extension.
Why are we not generating a QImode shift instruction?

-- 
Rask Ingemann Lambertsen


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