1 /* { dg-do run } */
2 /* { dg-require-effective-target htm } */
3 /* { dg-options "-O3 -march=zEC12 -mzarch --save-temps" } */
4 
5 /* __builtin_tbegin has to emit clobbers for all FPRs since the tbegin
6    instruction does not automatically preserves them.  If the
7    transaction body is fully contained in a function the backend tries
8    after reload to get rid of the FPR save/restore operations
9    triggered by the clobbers.  This testcase failed since the backend
10    was able to get rid of all FPR saves/restores and since these were
11    the only stack operations also of the entire stack space.  So even
12    the save/restore of the stack pointer was omitted in the end.
13    However, since the frame layout has been fixed before, the prologue
14    still generated the stack pointer decrement making foo return with
15    a modified stack pointer.  */
16 
17 void abort(void);
18 
19 void __attribute__((noinline))
foo(int a)20 foo (int a)
21 {
22   if (__builtin_tbegin (0) == 0)
23     __builtin_tend ();
24 }
25 
26 #ifdef __s390x__
27 #define GET_STACK_POINTER(SP)			\
28   asm volatile ("stg %%r15, %0" : "=QRST" (SP));
29 #else
30 #define GET_STACK_POINTER(SP)			\
31   asm volatile ("st %%r15, %0" : "=QR" (SP));
32 #endif
33 
main(void)34 int main(void)
35 {
36   unsigned long new_sp, old_sp;
37 
38   GET_STACK_POINTER (old_sp);
39   foo(42);
40   GET_STACK_POINTER (new_sp);
41 
42   if (old_sp != new_sp)
43     abort ();
44 
45   return 0;
46 }
47 
48 /* Make sure no FPR saves/restores are emitted.  */
49 /* { dg-final { scan-assembler-not "\tstd\t" } } */
50 /* { dg-final { scan-assembler-not "\tld\t" } } */
51