diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-19 09:26:09 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-19 09:26:09 +0000 |
commit | ca53beb103dca912691637608e17641c045071a2 (patch) | |
tree | 2b023726d21f6bfcb73860fcbf31cc52aa54697e /gcc/tree-ssa-loop-im.c | |
parent | ff6269a2c5982ab6351db35f158d7c0162d50416 (diff) | |
download | ppe42-gcc-ca53beb103dca912691637608e17641c045071a2.tar.gz ppe42-gcc-ca53beb103dca912691637608e17641c045071a2.zip |
PR tree-optimization/19828
* tree-ssa-loop-im.c: Add a TODO comment.
(movement_possibility): Return MOVE_PRESERVE_EXECUTION for calls
without side-effects.
* gcc.dg/tree-ssa/loop-7.c: New test.
* gcc.c-torture/execute/20050218-1.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95275 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-loop-im.c')
-rw-r--r-- | gcc/tree-ssa-loop-im.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 65a2a5fd48a..770b71b1208 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -38,6 +38,28 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "tree-pass.h" #include "flags.h" +/* TODO: Support for predicated code motion. I.e. + + while (1) + { + if (cond) + { + a = inv; + something; + } + } + + Where COND and INV are is invariants, but evaluating INV may trap or be + invalid from some other reason if !COND. This may be transformed to + + if (cond) + a = inv; + while (1) + { + if (cond) + something; + } */ + /* A type for the list of statements that have to be moved in order to be able to hoist an invariant computation. */ @@ -227,6 +249,28 @@ movement_possibility (tree stmt) || tree_could_trap_p (rhs)) return MOVE_PRESERVE_EXECUTION; + if (get_call_expr_in (stmt)) + { + /* While pure or const call is guaranteed to have no side effects, we + cannot move it arbitrarily. Consider code like + + char *s = something (); + + while (1) + { + if (s) + t = strlen (s); + else + t = 0; + } + + Here the strlen call cannot be moved out of the loop, even though + s is invariant. In addition to possibly creating a call with + invalid arguments, moving out a function call that is not executed + may cause performance regressions in case the call is costly and + not executed at all. */ + return MOVE_PRESERVE_EXECUTION; + } return MOVE_POSSIBLE; } |