diff options
-rw-r--r-- | gcc/common.opt | 4 | ||||
-rw-r--r-- | gcc/config/i386/i386.md | 17 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 9 | ||||
-rw-r--r-- | gcc/lto-wrapper.c | 7 | ||||
-rw-r--r-- | gcc/optc-save-gen.awk | 2 | ||||
-rw-r--r-- | gcc/opts.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr32803.c | 10 |
7 files changed, 55 insertions, 4 deletions
diff --git a/gcc/common.opt b/gcc/common.opt index 4af89ce..2ed818d 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -483,6 +483,10 @@ Og Common Optimization Optimize for debugging experience rather than speed or size. +Oz +Common Optimization +Optimize for space aggressively rather than speed. + Q Driver diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index f6d9c4b..862d933 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -2213,7 +2213,14 @@ case TYPE_IMOV: gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1])); if (get_attr_mode (insn) == MODE_SI) - return "mov{l}\t{%k1, %k0|%k0, %k1}"; + { + if (optimize_size > 1 + && TARGET_64BIT + && CONST_INT_P (operands[1]) + && IN_RANGE (INTVAL (operands[1]), -128, 127)) + return "push{q}\t%1\n\tpop{q}\t%0"; + return "mov{l}\t{%k1, %k0|%k0, %k1}"; + } else if (which_alternative == 4) return "movabs{q}\t{%1, %0|%0, %1}"; else if (ix86_use_lea_for_mov (insn, operands)) @@ -2431,6 +2438,14 @@ gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1])); if (ix86_use_lea_for_mov (insn, operands)) return "lea{l}\t{%E1, %0|%0, %E1}"; + else if (optimize_size > 1 + && CONST_INT_P (operands[1]) + && IN_RANGE (INTVAL (operands[1]), -128, 127)) + { + if (TARGET_64BIT) + return "push{q}\t%1\n\tpop{q}\t%q0"; + return "push{l}\t%1\n\tpop{l}\t%0"; + } else return "mov{l}\t{%1, %0|%0, %1}"; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index de552b5..ca62157 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -588,7 +588,7 @@ Objective-C and Objective-C++ Dialects}. -fipa-ra -fvariable-expansion-in-unroller -fvect-cost-model -fvpt @gol -fweb -fwhole-program -fwpa -fuse-linker-plugin -fzero-call-used-regs @gol --param @var{name}=@var{value} --O -O0 -O1 -O2 -O3 -Os -Ofast -Og} +-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -Oz} @item Program Instrumentation Options @xref{Instrumentation Options,,Program Instrumentation Options}. @@ -10734,6 +10734,13 @@ optimization flags except for those that may interfere with debugging: -fmove-loop-invariants -fmove-loop-stores -fssa-phiopt @gol -ftree-bit-ccp -ftree-dse -ftree-pta -ftree-sra} +@item -Oz +@opindex Oz +Optimize aggressively for size rather than speed. This may increase +the number of instructions executed if those instructions require +fewer bytes to encode. @option{-Oz} behaves similarly to @option{-Os} +including enabling most @option{-O2} optimizations. + @end table If you use multiple @option{-O} options, with or without level numbers, diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c index 54f642d..7d2b7e5 100644 --- a/gcc/lto-wrapper.c +++ b/gcc/lto-wrapper.c @@ -370,12 +370,14 @@ merge_and_complain (vec<cl_decoded_option> &decoded_options, case OPT_Ofast: case OPT_Og: case OPT_Os: + case OPT_Oz: existing_opt = -1; for (j = 0; j < decoded_options.length (); ++j) if (decoded_options[j].opt_index == OPT_O || decoded_options[j].opt_index == OPT_Ofast || decoded_options[j].opt_index == OPT_Og - || decoded_options[j].opt_index == OPT_Os) + || decoded_options[j].opt_index == OPT_Os + || decoded_options[j].opt_index == OPT_Oz) { existing_opt = j; break; @@ -407,6 +409,7 @@ merge_and_complain (vec<cl_decoded_option> &decoded_options, level = MAX (level, 1); break; case OPT_Os: + case OPT_Oz: level = MAX (level, 2); break; default: @@ -428,6 +431,7 @@ merge_and_complain (vec<cl_decoded_option> &decoded_options, level = MAX (level, 1); break; case OPT_Os: + case OPT_Oz: level = MAX (level, 2); break; default: @@ -725,6 +729,7 @@ append_compiler_options (obstack *argv_obstack, vec<cl_decoded_option> opts) case OPT_Ofast: case OPT_Og: case OPT_Os: + case OPT_Oz: break; case OPT_Xassembler: diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk index e363ac7..81c2db0 100644 --- a/gcc/optc-save-gen.awk +++ b/gcc/optc-save-gen.awk @@ -93,7 +93,7 @@ var_opt_char[1] = "optimize_size"; var_opt_char[2] = "optimize_debug"; var_opt_char[3] = "optimize_fast"; var_opt_range["optimize"] = "0, 255"; -var_opt_range["optimize_size"] = "0, 1"; +var_opt_range["optimize_size"] = "0, 2"; var_opt_range["optimize_debug"] = "0, 1"; var_opt_range["optimize_fast"] = "0, 1"; @@ -745,6 +745,15 @@ default_options_optimization (struct gcc_options *opts, opts->x_optimize_debug = 0; break; + case OPT_Oz: + opts->x_optimize_size = 2; + + /* Optimizing for size forces optimize to be 2. */ + opts->x_optimize = 2; + opts->x_optimize_fast = 0; + opts->x_optimize_debug = 0; + break; + case OPT_Ofast: /* -Ofast only adds flags to -O3. */ opts->x_optimize_size = 0; @@ -2609,6 +2618,7 @@ common_handle_option (struct gcc_options *opts, case OPT_Os: case OPT_Ofast: case OPT_Og: + case OPT_Oz: /* Currently handled in a prescan. */ break; diff --git a/gcc/testsuite/gcc.target/i386/pr32803.c b/gcc/testsuite/gcc.target/i386/pr32803.c new file mode 100644 index 0000000..f26f07a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32803.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-Oz" } */ + +int foo() +{ + return 25; +} + +/* { dg-final { scan-assembler "push" } } */ +/* { dg-final { scan-assembler "pop" } } */ |