Sometimes people write loops that they do not want optimized away, even when the compiler can replace those loops by a simple expression (or nothing). For such people, this patch adds a compiler option.
Bootstrapped on powerpc64-linux; regression check still in progress (with Init(1) to actually test anything). Segher 2016-04-01 Segher Boessenkool <seg...@kernel.crashing.org> * loop-init.c: Include some more stuff that really doesn't belong here, oh well. (loop_optimizer_init): Add empty asm statements in all gimple loops, if asked to. * common.opt: Add new option. --- gcc/common.opt | 4 ++++ gcc/loop-init.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/loop-init.c b/gcc/loop-init.c index 8634591..7c5dc24 100644 --- a/gcc/loop-init.c +++ b/gcc/loop-init.c @@ -24,6 +24,8 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "rtl.h" #include "tree.h" +#include "gimple.h" +#include "gimple-iterator.h" #include "cfghooks.h" #include "df.h" #include "regs.h" @@ -91,6 +93,19 @@ loop_optimizer_init (unsigned flags) /* Find the loops. */ current_loops = flow_loops_find (NULL); + + if (flag_never_gonna_give_you_up && current_ir_type () == IR_GIMPLE) + { + struct loop *loop; + FOR_EACH_LOOP (loop, 0) + if (loop->latch) + { + gasm *p = gimple_build_asm_vec ("", 0, 0, 0, 0); + gimple_asm_set_volatile (p, true); + gimple_stmt_iterator bsi = gsi_after_labels (loop->latch); + gsi_insert_before (&bsi, p, GSI_SAME_STMT); + } + } } else { diff --git a/gcc/common.opt b/gcc/common.opt index 0f3bb4e..b7c0a6a 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2002,6 +2002,10 @@ frerun-loop-opt Common Ignore Does nothing. Preserved for backward compatibility. +frickroll-all-loops +Common Report Var(flag_never_gonna_give_you_up) Init(0) Optimization +You know the rules, and so do I. + frounding-math Common Report Var(flag_rounding_math) Optimization SetByCombined Disable optimizations that assume default FP rounding behavior. -- 1.9.3