1 ; RUN: sed -e 's/SLHATTR/speculative_load_hardening/' %s | llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu | FileCheck %s --check-prefixes=CHECK,SLH
2 ; RUN: sed -e 's/SLHATTR//' %s | llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu | FileCheck %s --check-prefixes=CHECK,NOSLH
3 ; RUN: sed -e 's/SLHATTR/speculative_load_hardening/' %s | llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu -global-isel | FileCheck %s --check-prefixes=CHECK,SLH
4 ; RUN: sed -e 's/SLHATTR//' %s | llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu -global-isel | FileCheck %s --check-prefixes=CHECK,NOSLH
5 ; RUN: sed -e 's/SLHATTR/speculative_load_hardening/' %s | llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu -fast-isel | FileCheck %s --check-prefixes=CHECK,SLH
6 ; RUN: sed -e 's/SLHATTR//' %s | llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu -fast-isel | FileCheck %s --check-prefixes=CHECK,NOSLH
8 define i32 @f(ptr nocapture readonly %p, i32 %i, i32 %N) local_unnamed_addr SLHATTR {
13 ; NOSLH-NOT: cmp sp, #0
14 ; NOSLH-NOT: csetm x16, ne
16 ; SLH: mov [[TMPREG:x[0-9]+]], sp
17 ; SLH: and [[TMPREG]], [[TMPREG]], x16
18 ; SLH: mov sp, [[TMPREG]]
19 ; NOSLH-NOT: mov {{x[0-9]+}}, sp
20 ; NOSLH-NOT: and [[TMPREG:x[0-9]+]], [[TMPREG]], x16
21 ; NOSLH-NOT: mov sp, {{x[0-9]+}}
22 %call = tail call i32 @tail_callee(i32 %i)
25 ; NOSLH-NOT: cmp sp, #0
26 ; NOSLH-NOT: csetm x16, ne
27 %cmp = icmp slt i32 %call, %N
28 br i1 %cmp, label %if.then, label %return
29 ; CHECK: b.[[COND:(ge)|(lt)|(ne)|(eq)]]
31 if.then: ; preds = %entry
32 ; NOSLH-NOT: csel x16, x16, xzr, {{(lt)|(ge)|(eq)|(ne)}}
33 ; SLH-DAG: csel x16, x16, xzr, {{(lt)|(ge)|(eq)|(ne)}}
34 %idxprom = sext i32 %i to i64
35 %arrayidx = getelementptr inbounds i8, ptr %p, i64 %idxprom
36 %0 = load i8, ptr %arrayidx, align 1
37 ; CHECK-DAG: ldrb [[LOADED:w[0-9]+]],
38 %conv = zext i8 %0 to i32
41 ; SLH-DAG: csel x16, x16, xzr, [[COND]]
42 ; NOSLH-NOT: csel x16, x16, xzr, [[COND]]
43 return: ; preds = %entry, %if.then
44 %retval.0 = phi i32 [ %conv, %if.then ], [ 0, %entry ]
45 ; SLH: mov [[TMPREG:x[0-9]+]], sp
46 ; SLH: and [[TMPREG]], [[TMPREG]], x16
47 ; SLH: mov sp, [[TMPREG]]
48 ; NOSLH-NOT: mov {{x[0-9]+}}, sp
49 ; NOSLH-NOT: and [[TMPREG:x[0-9]+]], [[TMPREG]], x16
50 ; NOSLH-NOT: mov sp, {{x[0-9]+}}
54 ; Make sure that for a tail call, taint doesn't get put into SP twice.
55 define i32 @tail_caller(i32 %a) local_unnamed_addr SLHATTR {
56 ; CHECK-LABEL: tail_caller:
57 ; SLH: mov [[TMPREG:x[0-9]+]], sp
58 ; SLH: and [[TMPREG]], [[TMPREG]], x16
59 ; SLH: mov sp, [[TMPREG]]
60 ; NOSLH-NOT: mov {{x[0-9]+}}, sp
61 ; NOSLH-NOT: and [[TMPREG:x[0-9]+]], [[TMPREG]], x16
62 ; NOSLH-NOT: mov sp, {{x[0-9]+}}
65 %call = tail call i32 @tail_callee(i32 %a)
69 declare i32 @tail_callee(i32) local_unnamed_addr
71 ; Verify that no cb(n)z/tb(n)z instructions are produced when implementing
73 define i32 @compare_branch_zero(i32, i32) SLHATTR {
74 ; CHECK-LABEL: compare_branch_zero
75 %3 = icmp eq i32 %0, 0
76 br i1 %3, label %then, label %else
87 define i32 @test_branch_zero(i32, i32) SLHATTR {
88 ; CHECK-LABEL: test_branch_zero
90 %4 = icmp eq i32 %3, 0
91 br i1 %4, label %then, label %else
102 define i32 @landingpad(i32 %l0, i32 %l1) SLHATTR personality ptr @__gxx_personality_v0 {
103 ; CHECK-LABEL: landingpad
107 ; NOSLH-NOT: cmp sp, #0
108 ; NOSLH-NOT: csetm x16, ne
109 ; CHECK: bl _Z10throwing_fv
110 invoke void @_Z10throwing_fv()
111 to label %exit unwind label %lpad
116 %l4 = landingpad { ptr, i32 }
120 ; NOSLH-NOT: cmp sp, #0
121 ; NOSLH-NOT: csetm x16, ne
122 %l5 = extractvalue { ptr, i32 } %l4, 0
123 %l6 = tail call ptr @__cxa_begin_catch(ptr %l5)
124 %l7 = icmp sgt i32 %l0, %l1
125 br i1 %l7, label %then, label %else
126 ; GlobalISel lowers the branch to a b.ne sometimes instead of b.ge as expected..
127 ; CHECK: b.[[COND:(le)|(gt)|(ne)|(eq)]]
130 ; SLH-DAG: csel x16, x16, xzr, [[COND]]
131 %l9 = sdiv i32 %l0, %l1
135 ; SLH-DAG: csel x16, x16, xzr, {{(gt)|(le)|(eq)|(ne)}}
136 %l11 = sdiv i32 %l1, %l0
140 %l13 = phi i32 [ %l9, %then ], [ %l11, %else ]
141 tail call void @__cxa_end_catch()
145 %l15 = phi i32 [ %l13, %postif ], [ 0, %entry ]
149 declare i32 @__gxx_personality_v0(...)
150 declare void @_Z10throwing_fv() local_unnamed_addr
151 declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr
152 declare void @__cxa_end_catch() local_unnamed_addr