This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/50101] GCC 4.5 and 4.6 generate suboptimal code on ppc for countdown loops when the CTR register cannot be used
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 18 Aug 2011 08:58:28 +0000
- Subject: [Bug rtl-optimization/50101] GCC 4.5 and 4.6 generate suboptimal code on ppc for countdown loops when the CTR register cannot be used
- Auto-submitted: auto-generated
- References: <bug-50101-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50101
--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-18 08:58:28 UTC ---
(In reply to comment #3)
> (In reply to comment #2)
> > I suppose the CTR is introduced after RA in machine-dependent reorg? In which
> > case can the issue be fixed on branches by adjusting register cost of the CTR?
>
> No, the pattern would normally allocate the CTR, and has options to fall back
> to register, and memory. According to the comments in the source, because it
> is a JUMP_INSN, it has to provide reloads from memory in case it can't find a
> register. Previously, GCC was able to allocate a register, but now it doesn't
> seem to.
>
> Here is the pattern from rs6000.md:
>
> ;; We need to be able to do this for any operand, including MEM, or we
> ;; will cause reload to blow up since we don't allow output reloads on
> ;; JUMP_INSNs.
> ;; For the length attribute to be calculated correctly, the
> ;; label MUST be operand 0.
>
> (define_insn "*ctr<mode>_internal1"
> [(set (pc)
> (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
> (const_int 1))
> (label_ref (match_operand 0 "" ""))
> (pc)))
> (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
> (plus:P (match_dup 1)
> (const_int -1)))
> (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
> (clobber (match_scratch:P 4 "=X,X,&r,r"))]
> ""
> "*
> {
> if (which_alternative != 0)
> return \"#\";
> else if (get_attr_length (insn) == 4)
> return \"{bdn|bdnz} %l0\";
> else
> return \"bdz $+8\;b %l0\";
> }"
> [(set_attr "type" "branch")
> (set_attr "length" "*,12,16,16")])
>
> I will upload the rtl dump files as attachments.
Did you try pessimizing the non-ctr reg alternatives (and the memory
alternative even more)? Like adding ! to the non-ctr alternatives
and ? to the memory one? Not sure if those markers are looked at
by IRA though.