mips.c (override_options): Use mips_costs to derive the default branch cost.
authorRichard Sandiford <richard@codesourcery.com>
Mon, 23 Jul 2007 12:49:45 +0000 (12:49 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Mon, 23 Jul 2007 12:49:45 +0000 (12:49 +0000)
gcc/
* config/mips/mips.c (override_options): Use mips_costs to derive
the default branch cost.
* config/mips/mips.h (BRANCH_COST): Use mips_branch_cost rather
than mips_costs.
* config/mips/mips.opt (mbranch-cost=): New option.
* doc/invoke.texi (-mbrach-cost): Document new MIPS option.

gcc/testsuite/
* gcc.target/mips/branch-cost-1.c: New test.
* gcc.target/mips/branch-cost-2.c: Likewise.

From-SVN: r126846

gcc/ChangeLog
gcc/config/mips/mips.c
gcc/config/mips/mips.h
gcc/config/mips/mips.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/mips/branch-cost-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/branch-cost-2.c [new file with mode: 0644]

index 3c85d672dfef00b67968d3a5a73d0e1f9559a7ac..ad37fca1c92530c530246fd474eada9c4b6b7075 100644 (file)
@@ -1,3 +1,12 @@
+2007-07-23  Richard Sandiford  <richard@codesourcery.com>
+
+       * config/mips/mips.c (override_options): Use mips_costs to derive
+       the default branch cost.
+       * config/mips/mips.h (BRANCH_COST): Use mips_branch_cost rather
+       than mips_costs.
+       * config/mips/mips.opt (mbranch-cost=): New option.
+       * doc/invoke.texi (-mbrach-cost): Document new MIPS option.
+
 2007-07-23  Richard Sandiford  <richard@codesourcery.com>
 
        * config/mips/mips.h (GR_REG_CLASS_P, COP_REG_CLASS_P): Delete.
index a7adf170cbc0f4c6bf3e15335e012922c5dd4b24..f42fe77eaf19cb2e17a166bcc4b4ac9f408cf2c4 100644 (file)
@@ -5047,6 +5047,11 @@ override_options (void)
   else
     mips_cost = &mips_rtx_cost_data[mips_tune];
 
+  /* If the user hasn't specified a branch cost, use the processor's
+     default.  */
+  if (mips_branch_cost == 0)
+    mips_branch_cost = mips_cost->branch_cost;
+
   if ((target_flags_explicit & MASK_64BIT) != 0)
     {
       /* The user specified the size of the integer registers.  Make sure
index dbc947d4b6b573c378a60c08af16dadc8225268b..2496986c881216ea2927596d98458a12c2024cbd 100644 (file)
@@ -2326,7 +2326,7 @@ typedef struct mips_args {
 /* A C expression for the cost of a branch instruction.  A value of
    1 is the default; other values are interpreted relative to that.  */
 
-#define BRANCH_COST mips_cost->branch_cost
+#define BRANCH_COST mips_branch_cost
 #define LOGICAL_OP_NON_SHORT_CIRCUIT 0
 
 /* If defined, modifies the length assigned to instruction INSN as a
index f7e751fb71322d1ec04a8fb56bb7c5e84a7920aa..7e6dd37c7259c4b02813810eb3a115dbeef84a0f 100644 (file)
@@ -35,6 +35,10 @@ march=
 Target RejectNegative Joined Var(mips_arch_string)
 -march=ISA     Generate code for the given ISA
 
+mbranch-cost=
+Target RejectNegative Joined UInteger Var(mips_branch_cost)
+-mbranch-cost=COST     Set the cost of branches to roughly COST instructions
+
 mbranch-likely
 Target Report Mask(BRANCHLIKELY)
 Use Branch Likely instructions, overriding the architecture default
index c954b9fe9d5d00f5f34ca93a2082a1e2fecf972f..116513ea031eeb8c91aa666b88ff62f390d0346c 100644 (file)
@@ -638,7 +638,7 @@ Objective-C and Objective-C++ Dialects}.
 -mfix-vr4120  -mno-fix-vr4120  -mfix-vr4130  -mno-fix-vr4130 @gol
 -mfix-sb1  -mno-fix-sb1 @gol
 -mflush-func=@var{func}  -mno-flush-func @gol
--mbranch-likely  -mno-branch-likely @gol
+-mbranch-cost=@var{num}  -mbranch-likely  -mno-branch-likely @gol
 -mfp-exceptions -mno-fp-exceptions @gol
 -mvr4130-align -mno-vr4130-align}
 
@@ -11915,6 +11915,13 @@ memory range, and the number 3 (to flush both caches).  The default
 depends on the target GCC was configured for, but commonly is either
 @samp{_flush_func} or @samp{__cpu_flush}.
 
+@item mbranch-cost=@var{num}
+@opindex mbranch-cost
+Set the cost of branches to roughly @var{num} ``simple'' instructions.
+This cost is only a heuristic and is not guaranteed to produce
+consistent results across releases.  A zero cost redundantly selects
+the default, which is based on the @option{-mtune} setting.
+
 @item -mbranch-likely
 @itemx -mno-branch-likely
 @opindex mbranch-likely
index 5f21f1bd03cd91789919f1476dedd50f51594e7b..bc46a5d4091f9c78dd0d43e5065b41422b52c171 100644 (file)
@@ -1,3 +1,8 @@
+2007-07-23  Richard Sandiford  <richard@codesourcery.com>
+
+       * gcc.target/mips/branch-cost-1.c: New test.
+       * gcc.target/mips/branch-cost-2.c: Likewise.
+
 2007-07-23  Christopher D. Rickett  <crickett@lanl.gov>
 
        PR fortran/32732
diff --git a/gcc/testsuite/gcc.target/mips/branch-cost-1.c b/gcc/testsuite/gcc.target/mips/branch-cost-1.c
new file mode 100644 (file)
index 0000000..3b2c80d
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-mips-options "-mbranch-cost=1 -mips64 -O2" } */
+int
+foo (int x, int y, int z, int k)
+{
+  return x == k ? x + y : z - x;
+}
+/* { dg-final { scan-assembler-not "\t(movz|movn)\t" } } */
+/* { dg-final { scan-assembler "\t(bne|beq)\t" } } */
diff --git a/gcc/testsuite/gcc.target/mips/branch-cost-2.c b/gcc/testsuite/gcc.target/mips/branch-cost-2.c
new file mode 100644 (file)
index 0000000..356def2
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-mips-options "-mbranch-cost=10 -mips64 -O2" } */
+int
+foo (int x, int y, int z, int k)
+{
+  return x == k ? x + y : z - x;
+}
+/* { dg-final { scan-assembler "\t(movz|movn)\t" } } */
+/* { dg-final { scan-assembler-not "\t(bne|beq)\t" } } */