- group "casts"; begin
- let void_ptr = pointer_type i8_type in
-
- (* RUN: grep "%build_trunc = trunc i32 %P1 to i8" < %t.ll
- * RUN: grep "%build_trunc2 = trunc i32 %P1 to i8" < %t.ll
- * RUN: grep "%build_trunc3 = trunc i32 %P1 to i8" < %t.ll
- * RUN: grep "%build_zext = zext i8 %build_trunc to i32" < %t.ll
- * RUN: grep "%build_zext2 = zext i8 %build_trunc to i32" < %t.ll
- * RUN: grep "%build_sext = sext i32 %build_zext to i64" < %t.ll
- * RUN: grep "%build_sext2 = sext i32 %build_zext to i64" < %t.ll
- * RUN: grep "%build_sext3 = sext i32 %build_zext to i64" < %t.ll
- * RUN: grep "%build_uitofp = uitofp i64 %build_sext to float" < %t.ll
- * RUN: grep "%build_sitofp = sitofp i32 %build_zext to double" < %t.ll
- * RUN: grep "%build_fptoui = fptoui float %build_uitofp to i32" < %t.ll
- * RUN: grep "%build_fptosi = fptosi double %build_sitofp to i64" < %t.ll
- * RUN: grep "%build_fptrunc = fptrunc double %build_sitofp to float" < %t.ll
- * RUN: grep "%build_fptrunc2 = fptrunc double %build_sitofp to float" < %t.ll
- * RUN: grep "%build_fpext = fpext float %build_fptrunc to double" < %t.ll
- * RUN: grep "%build_fpext2 = fpext float %build_fptrunc to double" < %t.ll
- * RUN: grep "%build_inttoptr = inttoptr i32 %P1 to i8\*" < %t.ll
- * RUN: grep "%build_ptrtoint = ptrtoint i8\* %build_inttoptr to i64" < %t.ll
- * RUN: grep "%build_ptrtoint2 = ptrtoint i8\* %build_inttoptr to i64" < %t.ll
- * RUN: grep "%build_bitcast = bitcast i64 %build_ptrtoint to double" < %t.ll
- * RUN: grep "%build_bitcast2 = bitcast i64 %build_ptrtoint to double" < %t.ll
- * RUN: grep "%build_bitcast3 = bitcast i64 %build_ptrtoint to double" < %t.ll
- * RUN: grep "%build_bitcast4 = bitcast i64 %build_ptrtoint to double" < %t.ll
- * RUN: grep "%build_pointercast = bitcast i8\* %build_inttoptr to i16*" < %t.ll
- *)
- let inst28 = build_trunc p1 i8_type "build_trunc" atentry in
- let inst29 = build_zext inst28 i32_type "build_zext" atentry in
- let inst30 = build_sext inst29 i64_type "build_sext" atentry in
- let inst31 = build_uitofp inst30 float_type "build_uitofp" atentry in
- let inst32 = build_sitofp inst29 double_type "build_sitofp" atentry in
- ignore(build_fptoui inst31 i32_type "build_fptoui" atentry);
- ignore(build_fptosi inst32 i64_type "build_fptosi" atentry);
- let inst35 = build_fptrunc inst32 float_type "build_fptrunc" atentry in
- ignore(build_fpext inst35 double_type "build_fpext" atentry);
- let inst37 = build_inttoptr p1 void_ptr "build_inttoptr" atentry in
- let inst38 = build_ptrtoint inst37 i64_type "build_ptrtoint" atentry in
- ignore(build_bitcast inst38 double_type "build_bitcast" atentry);
- ignore(build_zext_or_bitcast inst38 double_type "build_bitcast2" atentry);
- ignore(build_sext_or_bitcast inst38 double_type "build_bitcast3" atentry);
- ignore(build_trunc_or_bitcast inst38 double_type "build_bitcast4" atentry);
- ignore(build_pointercast inst37 (pointer_type i16_type) "build_pointercast" atentry);
-
- ignore(build_zext_or_bitcast inst28 i32_type "build_zext2" atentry);
- ignore(build_sext_or_bitcast inst29 i64_type "build_sext2" atentry);
- ignore(build_trunc_or_bitcast p1 i8_type "build_trunc2" atentry);
- ignore(build_pointercast inst37 i64_type "build_ptrtoint2" atentry);
- ignore(build_intcast inst29 i64_type "build_sext3" atentry);
- ignore(build_intcast p1 i8_type "build_trunc3" atentry);
- ignore(build_fpcast inst35 double_type "build_fpext2" atentry);
- ignore(build_fpcast inst32 float_type "build_fptrunc2" atentry);
- end;
-
- group "comparisons"; begin
- (* RUN: grep "%build_icmp_ne = icmp ne i32 %P1, %P2" < %t.ll
- * RUN: grep "%build_icmp_sle = icmp sle i32 %P2, %P1" < %t.ll
- * RUN: grep "%build_fcmp_false = fcmp false float %F1, %F2" < %t.ll
- * RUN: grep "%build_fcmp_true = fcmp true float %F2, %F1" < %t.ll
- * RUN: grep "%build_is_null.*= icmp eq.*%X0,.*null" < %t.ll
- * RUN: grep "%build_is_not_null = icmp ne i8\* %X1, null" < %t.ll
- * RUN: grep "%build_ptrdiff" < %t.ll
- *)
- ignore (build_icmp Icmp.Ne p1 p2 "build_icmp_ne" atentry);
- ignore (build_icmp Icmp.Sle p2 p1 "build_icmp_sle" atentry);
- ignore (build_fcmp Fcmp.False f1 f2 "build_fcmp_false" atentry);
- ignore (build_fcmp Fcmp.True f2 f1 "build_fcmp_true" atentry);
- let g0 = declare_global (pointer_type i8_type) "g0" m in
- let g1 = declare_global (pointer_type i8_type) "g1" m in
- let p0 = build_load g0 "X0" atentry in
- let p1 = build_load g1 "X1" atentry in
- ignore (build_is_null p0 "build_is_null" atentry);
- ignore (build_is_not_null p1 "build_is_not_null" atentry);
- ignore (build_ptrdiff p1 p0 "build_ptrdiff" atentry);
- end;
-
- group "miscellaneous"; begin
- (* RUN: grep "%build_call = tail call cc63 i32 @.*(i32 signext %P2, i32 %P1)" < %t.ll
- * RUN: grep "%build_select = select i1 %build_icmp, i32 %P1, i32 %P2" < %t.ll
- * RUN: grep "%build_va_arg = va_arg i8\*\* null, i32" < %t.ll
- * RUN: grep "%build_extractelement = extractelement <4 x i32> %Vec1, i32 %P2" < %t.ll
- * RUN: grep "%build_insertelement = insertelement <4 x i32> %Vec1, i32 %P1, i32 %P2" < %t.ll
- * RUN: grep "%build_shufflevector = shufflevector <4 x i32> %Vec1, <4 x i32> %Vec2, <4 x i32> <i32 1, i32 1, i32 0, i32 0>" < %t.ll
- * RUN: grep "%build_insertvalue0 = insertvalue.*%bl, i32 1, 0" < %t.ll
- * RUN: grep "%build_extractvalue = extractvalue.*%build_insertvalue1, 1" < %t.ll
- *)
- let ci = build_call fn [| p2; p1 |] "build_call" atentry in
- insist (CallConv.c = instruction_call_conv ci);
- set_instruction_call_conv 63 ci;
- insist (63 = instruction_call_conv ci);
- insist (not (is_tail_call ci));
- set_tail_call true ci;
- insist (is_tail_call ci);
- add_instruction_param_attr ci 1 Attribute.Sext;
- add_instruction_param_attr ci 2 Attribute.Noalias;
- remove_instruction_param_attr ci 2 Attribute.Noalias;
-
- let inst46 = build_icmp Icmp.Eq p1 p2 "build_icmp" atentry in
- ignore (build_select inst46 p1 p2 "build_select" atentry);
- ignore (build_va_arg
- (const_null (pointer_type (pointer_type i8_type)))
- i32_type "build_va_arg" atentry);
-
- (* Set up some vector vregs. *)
- let one = const_int i32_type 1 in
- let zero = const_int i32_type 0 in
- let t1 = const_vector [| one; zero; one; zero |] in
- let t2 = const_vector [| zero; one; zero; one |] in
- let t3 = const_vector [| one; one; zero; zero |] in
- let vec1 = build_insertelement t1 p1 p2 "Vec1" atentry in
- let vec2 = build_insertelement t2 p1 p2 "Vec2" atentry in
- let sty = struct_type context [| i32_type; i8_type |] in
-
- ignore (build_extractelement vec1 p2 "build_extractelement" atentry);
- ignore (build_insertelement vec1 p1 p2 "build_insertelement" atentry);
- ignore (build_shufflevector vec1 vec2 t3 "build_shufflevector" atentry);
-
- let p = build_alloca sty "ba" atentry in
- let agg = build_load p "bl" atentry in
- let agg0 = build_insertvalue agg (const_int i32_type 1) 0
- "build_insertvalue0" atentry in
- let agg1 = build_insertvalue agg0 (const_int i8_type 2) 1
- "build_insertvalue1" atentry in
- ignore (build_extractvalue agg1 1 "build_extractvalue" atentry)
- end;
-
- group "metadata"; begin
- (* RUN: grep '%metadata = add i32 %P1, %P2, !test !0' < %t.ll
- * RUN: grep '!0 = metadata !{i32 1, metadata !"metadata test"}' < %t.ll
- *)
- let i = build_add p1 p2 "metadata" atentry in
- insist ((has_metadata i) = false);
-
- let m1 = const_int i32_type 1 in
- let m2 = mdstring context "metadata test" in
- let md = mdnode context [| m1; m2 |] in
-
- let kind = mdkind_id context "test" in
- set_metadata i kind md;
-
- insist ((has_metadata i) = true);
- insist ((metadata i kind) = Some md);
-
- clear_metadata i kind;
-
- insist ((has_metadata i) = false);
- insist ((metadata i kind) = None);
-
- set_metadata i kind md
- end;
-
- group "dbg"; begin
- (* RUN: grep '%dbg = add i32 %P1, %P2, !dbg !1' < %t.ll
- * RUN: grep '!1 = metadata !{i32 2, i32 3, metadata !2, metadata !2}' < %t.ll
- *)
- insist ((current_debug_location atentry) = None);
-
- let m_line = const_int i32_type 2 in
- let m_col = const_int i32_type 3 in
- let m_scope = mdnode context [| |] in
- let m_inlined = mdnode context [| |] in
- let md = mdnode context [| m_line; m_col; m_scope; m_inlined |] in
- set_current_debug_location atentry md;
-
- insist ((current_debug_location atentry) = Some md);
-
- let i = build_add p1 p2 "dbg" atentry in
- insist ((has_metadata i) = true);
-
- clear_current_debug_location atentry
- end;
-