Home | History | Annotate | Download | only in Inline
      1 ; RUN: opt < %s -inline -S | FileCheck %s
      2 
      3 ; Test that functions with attribute optnone are not inlined.
      4 ; Also test that only functions with attribute alwaysinline are
      5 ; valid candidates for inlining if the caller has the optnone attribute.
      6 
      7 ; Function Attrs: alwaysinline nounwind readnone uwtable
      8 define i32 @alwaysInlineFunction(i32 %a) #0 {
      9 entry:
     10   %mul = mul i32 %a, %a
     11   ret i32 %mul
     12 }
     13 
     14 ; Function Attrs: nounwind readnone uwtable
     15 define i32 @simpleFunction(i32 %a) #1 {
     16 entry:
     17   %add = add i32 %a, %a
     18   ret i32 %add
     19 }
     20 
     21 ; Function Attrs: nounwind noinline optnone readnone uwtable
     22 define i32 @OptnoneFunction(i32 %a) #2 {
     23 entry:
     24   %0 = tail call i32 @alwaysInlineFunction(i32 %a)
     25   %1 = tail call i32 @simpleFunction(i32 %a)
     26   %add = add i32 %0, %1
     27   ret i32 %add
     28 }
     29 
     30 ; CHECK-LABEL: @OptnoneFunction
     31 ; CHECK-NOT: call i32 @alwaysInlineFunction(i32 %a)
     32 ; CHECK: call i32 @simpleFunction(i32 %a)
     33 ; CHECK: ret
     34 
     35 ; Function Attrs: nounwind readnone uwtable
     36 define i32 @bar(i32 %a) #1 {
     37 entry:
     38   %0 = tail call i32 @OptnoneFunction(i32 5)
     39   %1 = tail call i32 @simpleFunction(i32 6)
     40   %add = add i32 %0, %1
     41   ret i32 %add
     42 }
     43 
     44 ; CHECK-LABEL: @bar
     45 ; CHECK: call i32 @OptnoneFunction(i32 5)
     46 ; CHECK-NOT: call i32 @simpleFunction(i32 6)
     47 ; CHECK: ret
     48 
     49 
     50 attributes #0 = { alwaysinline nounwind readnone uwtable }
     51 attributes #1 = { nounwind readnone uwtable }
     52 attributes #2 = { nounwind noinline optnone readnone uwtable }
     53