Skip to content

Commit 06fbd2c

Browse files
committed
fixup! arcv: apex: Add LTO testsuite for APEX intrinsics.
1 parent 3ab4fa7 commit 06fbd2c

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* { dg-lto-do link } */
2+
/* { dg-lto-options { { -flto -O2 -fdump-tree-optimized -save-temps } } } */
3+
4+
/* Test that intrinsics optimized away don't cause crashes during LTO.
5+
This test registers multiple intrinsics but only uses some of them,
6+
allowing the optimizer to remove the unused ones. */
7+
8+
int func_apex_used1 (int, int);
9+
#pragma intrinsic (func_apex_used1, "insn_apex_used1", 1, "XC")
10+
11+
int func_apex_unused (int, int);
12+
#pragma intrinsic (func_apex_unused, "insn_apex_unused", 2, "XS")
13+
14+
int func_apex_used2 (int, int);
15+
#pragma intrinsic (func_apex_used2, "insn_apex_used2", 3, "XC")
16+
17+
extern int bar (int);
18+
19+
static int
20+
func_apex_unused_helper (int a, int b)
21+
{
22+
return func_apex_unused (a, b);
23+
}
24+
25+
int
26+
main (void)
27+
{
28+
/* Only use func_apex_used1 and func_apex_used2.
29+
func_apex_unused should be optimized away. */
30+
int x = func_apex_used1 (5, 10);
31+
int y = func_apex_used2 (x, 15);
32+
return bar (y);
33+
}
34+
35+
/* Verify that only the used intrinsics appear in the optimized output. */
36+
/* { dg-final { scan-ltrans-tree-dump "func_apex_used1" "optimized" } } */
37+
/* { dg-final { scan-ltrans-tree-dump "func_apex_used2" "optimized" } } */
38+
/* { dg-final { scan-ltrans-tree-dump "func_apex_from_other" "optimized" } } */
39+
40+
/* Verify that the unused intrinsic is NOT in the optimized output. */
41+
/* { dg-final { scan-ltrans-tree-dump-not "func_apex_unused" "optimized" } } */
42+
/* { dg-final { scan-ltrans-tree-dump-not "func_apex_also_unused" "optimized" } } */
43+
44+
/* Verify that only used intrinsics have .extInstruction directives. */
45+
/* { dg-final { scan-ltrans-assembler "\\.extInstruction insn_apex_used1,1,XC" } } */
46+
/* { dg-final { scan-ltrans-assembler "\\.extInstruction insn_apex_used2,3,XC" } } */
47+
/* { dg-final { scan-ltrans-assembler "\\.extInstruction insn_apex_from_other,4,XS" } } */
48+
49+
/* Verify the actual instruction usage in assembly. */
50+
/* { dg-final { scan-ltrans-assembler-times "insn_apex_used1\\s+a\[0-9\]+,a\[0-9\]+,10" 1 } } */
51+
/* { dg-final { scan-ltrans-assembler-times "insn_apex_used2\\s+a\[0-9\]+,a\[0-9\]+,15" 1 } } */
52+
/* { dg-final { scan-ltrans-assembler-times "insn_apex_from_other\\s+a\[0-9\]+,a\[0-9\]+,20" 1 } } */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
int func_apex_from_other (int, int);
3+
#pragma intrinsic (func_apex_from_other, "insn_apex_from_other", 4, "XS")
4+
5+
int func_apex_also_unused (int, int);
6+
#pragma intrinsic (func_apex_also_unused, "insn_apex_also_unused", 5, "XC")
7+
8+
static int
9+
func_apex_also_unused_helper (int a, int b)
10+
{
11+
return func_apex_also_unused (a, b);
12+
}
13+
14+
int
15+
bar (int val)
16+
{
17+
/* Only use func_apex_from_other.
18+
func_apex_also_unused should be optimized away. */
19+
return func_apex_from_other (val, 20);
20+
}

0 commit comments

Comments
 (0)