diff options
author | Claudiu Zissulescu <claziss@synopsys.com> | 2017-06-01 11:42:49 +0200 |
---|---|---|
committer | Claudiu Zissulescu <claziss@gcc.gnu.org> | 2017-06-01 11:42:49 +0200 |
commit | 2daad50b025d4db0492cf14390ba76272f2df015 (patch) | |
tree | 88daa1be2a4a806cb29bc537e8228e901f7240ba | |
parent | 6f70ebc3d13809a2846a0831e190e5633aa9b688 (diff) | |
download | gcc-2daad50b025d4db0492cf14390ba76272f2df015.zip gcc-2daad50b025d4db0492cf14390ba76272f2df015.tar.gz gcc-2daad50b025d4db0492cf14390ba76272f2df015.tar.bz2 |
[ARC] Prevent moving stores to the frame before the stack adjustment.
If the stack pointer is needed, emit a special barrier that will prevent
the scheduler from moving stores to the frame before the stack adjustment.
For example:
[snip]
mov_s fp,sp ; frame pointer is set here
[snip]
st r1,[fp,-24] ; frame pointer is used here
[snip]
sub_s sp,sp,0x20 ; stack pointer adjusted
So we can easily see that any interrupt between the `st` and `sub`
instruction will lead to faulty code as the interrupt routine will use
a faulty sp register, and, potentially, overwriting the value stored
by 'st' instruction. Thus, adding a scheduler barrier will force the
compiler to emit the `sub` instruction before the store one.
2017-06-01 Claudiu Zissulescu <claziss@synopsys.com>
* config/arc/arc.c (arc_expand_prologue): Emit a special barrier
to prevent store reordering.
* config/arc/arc.md (UNSPEC_ARC_STKTIE): Define.
(type): Add block type.
(stack_tie): Define special instruction to be used in
expand_prologue.
From-SVN: r248781
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/config/arc/arc.c | 10 | ||||
-rw-r--r-- | gcc/config/arc/arc.md | 15 |
3 files changed, 32 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 867947a..92a7c0a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2017-06-01 Claudiu Zissulescu <claziss@synopsys.com> + * config/arc/arc.c (arc_expand_prologue): Emit a special barrier + to prevent store reordering. + * config/arc/arc.md (UNSPEC_ARC_STKTIE): Define. + (type): Add block type. + (stack_tie): Define special instruction to be used in + expand_prologue. + +2017-06-01 Claudiu Zissulescu <claziss@synopsys.com> + * config/arc/arc.md (commutative_binary_comparison): Remove 'I' constraint. It is not valid for the pattern. (noncommutative_binary_comparison): Likewise. diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c index a45e12b..caf01c8 100644 --- a/gcc/config/arc/arc.c +++ b/gcc/config/arc/arc.c @@ -2968,7 +2968,15 @@ arc_expand_prologue (void) frame_size_to_allocate -= first_offset; /* Allocate the stack frame. */ if (frame_size_to_allocate > 0) - frame_stack_add ((HOST_WIDE_INT) 0 - frame_size_to_allocate); + { + frame_stack_add ((HOST_WIDE_INT) 0 - frame_size_to_allocate); + /* If the frame pointer is needed, emit a special barrier that + will prevent the scheduler from moving stores to the frame + before the stack adjustment. */ + if (arc_frame_pointer_needed ()) + emit_insn (gen_stack_tie (stack_pointer_rtx, + hard_frame_pointer_rtx)); + } /* Setup the gp register, if needed. */ if (crtl->uses_pic_offset_table) diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md index b53ec02..5014138 100644 --- a/gcc/config/arc/arc.md +++ b/gcc/config/arc/arc.md @@ -135,6 +135,7 @@ UNSPEC_ARC_VMAC2HU UNSPEC_ARC_VMPY2H UNSPEC_ARC_VMPY2HU + UNSPEC_ARC_STKTIE ]) (define_c_enum "vunspec" [ @@ -205,7 +206,7 @@ simd_vcompare, simd_vpermute, simd_vpack, simd_vpack_with_acc, simd_valign, simd_valign_with_acc, simd_vcontrol, simd_vspecial_3cycle, simd_vspecial_4cycle, simd_dma, mul16_em, div_rem, - fpu" + fpu, block" (cond [(eq_attr "is_sfunc" "yes") (cond [(match_test "!TARGET_LONG_CALLS_SET && (!TARGET_MEDIUM_CALLS || GET_CODE (PATTERN (insn)) != COND_EXEC)") (const_string "call") (match_test "flag_pic") (const_string "sfunc")] @@ -6606,6 +6607,18 @@ (set_attr "predicable" "yes,no,no,yes,no") (set_attr "cond" "canuse,nocond,nocond,canuse_limm,nocond")]) +(define_insn "stack_tie" + [(set (mem:BLK (scratch)) + (unspec:BLK [(match_operand:SI 0 "register_operand" "rb") + (match_operand:SI 1 "register_operand" "rb")] + UNSPEC_ARC_STKTIE))] + "" + "" + [(set_attr "length" "0") + (set_attr "iscompact" "false") + (set_attr "type" "block")] + ) + ;; include the arc-FPX instructions (include "fpx.md") |