User account creation filtered due to spam.

Bug 19705 - -fno-branch-count-reg doesn't prevent decrement and branch instructions on a count register
Summary: -fno-branch-count-reg doesn't prevent decrement and branch instructions on a ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.0.0
: P2 minor
Target Milestone: ---
Assignee: Martin Sebor
URL:
Keywords: documentation
Depends on:
Blocks:
 
Reported: 2005-01-30 05:58 UTC by Andrew Pinski
Modified: 2016-03-07 17:11 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-*-*
Build:
Known to work:
Known to fail: 4.9.3, 5.3.0, 6.0
Last reconfirmed: 2016-01-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-01-30 05:58:22 UTC
Hmm, this is werid, why cannot I turn off doloop optimization with the -fno-branch-count-reg when I 
also turn off ivopts?  I should be able to when I want to look at the interaction between those two 
optimizations (options).
Testcase:
int foo (int x)
{
    int i= x;
    do {
        x *= 2;
    } while (--i);
    return x;
}

Compile with -O2 -fno-branch-count-reg -fno-ivopts and see there still is a bdnz in there.
but compile with -O2 -fno-branch-count-reg and you don't get the bdnz.
Comment 1 Andrew Pinski 2005-01-30 06:08:33 UTC
Werid it is combine which is doing it.  Hmm and this is not a regression.

Either the documention needs updating or the targets need to turn off these patterns when -fno-
branch-count-reg is supplied.
Comment 2 Andrew Pinski 2005-02-20 14:17:17 UTC
Confirmed, the documention just needs to changed as that -fno-branch-count-reg only turns off the 
extra analysis and that you can still get code using the branch counter even when using this option.
Comment 3 Alan Modra 2005-09-01 14:05:40 UTC
Or make the doloop insn patterns conditional on flag_branch_on_count_reg?
Comment 4 Andrew Pinski 2006-03-05 03:12:14 UTC
(In reply to comment #3)
> Or make the doloop insn patterns conditional on flag_branch_on_count_reg?
I had this discussion with David Edelsohn and he said that was not the correct approach.
Comment 5 Martin Sebor 2016-01-28 01:10:06 UTC
I spent a bit of time looking at this today (more than I should have).

Based on the comments and based on my own testing and debugging, the Summary of this bug isn't correct: the -fno-branch-count-reg option does disable the doloop optimization (even when -fno-ivopts).  What's not correct is the description of the effects of the option in the manual:

Do not use "decrement and branch" instructions on a count register, but instead generate a sequence of instructions that decrement a register, compare it against zero, then branch based upon the result.

I've adjusted the Summary to reflect that.

That said, I'm not sure what would be a meaningful update to the documentation.  Saying that the -fno-branch-count-reg option may not actually do what its name implies it's meant to do because there's some other pass that might do the opposite doesn't seem very helpful.

FWIW, I was curious to know what pass is responsible for inserting the bdnz instruction.  It seems that it's the combine pass and only in 32-bits.  That's the first pass where I see the ctrsi_internal1 pattern introduced for the test case.  (powerpc64 doesn't emit bdnz when -fno-branch-count-reg is used, at least not for the test case.)

Anyway, with this background my opinion, for whatever it's worth, is that if the purpose of the -fno-branch-count-reg option is to let users (as opposed to GCC developers) control the kind of code that GCC emits then this seems like a bug in the compiler that should be fixed by changing it to avoid emitting the ctr<mode>_internal* patterns.  Otherwise, if its purpose is to let GCC developers control whether or not the doloop pass runs, then that's how the option should be documented.  (I do realize that despite what the manual suggests these options are primarily used for debugging GCC so perhaps the second alternative is the way to go.)
Comment 6 Martin Sebor 2016-02-11 22:00:42 UTC
Documentation patch posted for review:
  https://gcc.gnu.org/ml/gcc-patches/2016-02/msg00809.html
Comment 7 Martin Sebor 2016-03-07 17:10:44 UTC
Author: msebor
Date: Mon Mar  7 17:10:12 2016
New Revision: 234039

URL: https://gcc.gnu.org/viewcvs?rev=234039&root=gcc&view=rev
Log:
PR rtl-optimization/19705 - -fno-branch-count-reg doesn't prevent decrement
	and branch instructions on a count register

gcc/ChangeLog:
2016-03-07  Martin Sebor  <msebor@redhat.com>

	PR rtl-optimization/19705
	* doc/invoke.texi (Options That Control Optimization): Clarify
	-fno-branch-count-reg.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/invoke.texi
Comment 8 Martin Sebor 2016-03-07 17:11:24 UTC
Documentation clarified in r234039.