1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -mtriple=arm64-darwin-unknown -S -consthoist < %s | FileCheck %s
4 ; Make sure we hoist constants out of intrinsics.
6 define void @test_stxr(i64* %ptr) {
7 ; CHECK-LABEL: @test_stxr(
9 ; CHECK-NEXT: [[CONST:%.*]] = bitcast i64 -9223372036317904832 to i64
10 ; CHECK-NEXT: [[PTR_0:%.*]] = getelementptr i64, i64* [[PTR:%.*]], i64 0
11 ; CHECK-NEXT: [[CONST_MAT:%.*]] = add i64 [[CONST]], -64
12 ; CHECK-NEXT: [[BAR_0:%.*]] = call i32 @llvm.aarch64.stxr.p0i64(i64 [[CONST_MAT]], i64* [[PTR_0]])
13 ; CHECK-NEXT: [[PTR_1:%.*]] = getelementptr i64, i64* [[PTR]], i64 1
14 ; CHECK-NEXT: [[BAR_1:%.*]] = call i32 @llvm.aarch64.stxr.p0i64(i64 [[CONST]], i64* [[PTR_1]])
15 ; CHECK-NEXT: [[PTR_2:%.*]] = getelementptr i64, i64* [[PTR]], i64 2
16 ; CHECK-NEXT: [[CONST_MAT1:%.*]] = add i64 [[CONST]], 64
17 ; CHECK-NEXT: [[BAR_2:%.*]] = call i32 @llvm.aarch64.stxr.p0i64(i64 [[CONST_MAT1]], i64* [[PTR_2]])
18 ; CHECK-NEXT: [[PTR_3:%.*]] = getelementptr i64, i64* [[PTR]], i64 3
19 ; CHECK-NEXT: [[CONST_MAT2:%.*]] = add i64 [[CONST]], 128
20 ; CHECK-NEXT: [[BAR_3:%.*]] = call i32 @llvm.aarch64.stxr.p0i64(i64 [[CONST_MAT2]], i64* [[PTR_3]])
21 ; CHECK-NEXT: ret void
24 %ptr.0 = getelementptr i64, i64* %ptr, i64 0
25 %bar.0 = call i32 @llvm.aarch64.stxr.p0i64(i64 -9223372036317904896, i64* %ptr.0)
26 %ptr.1 = getelementptr i64, i64* %ptr, i64 1
27 %bar.1 = call i32 @llvm.aarch64.stxr.p0i64(i64 -9223372036317904832, i64* %ptr.1)
28 %ptr.2 = getelementptr i64, i64* %ptr, i64 2
29 %bar.2 = call i32 @llvm.aarch64.stxr.p0i64(i64 -9223372036317904768, i64* %ptr.2)
30 %ptr.3 = getelementptr i64, i64* %ptr, i64 3
31 %bar.3 = call i32 @llvm.aarch64.stxr.p0i64(i64 -9223372036317904704, i64* %ptr.3)
35 declare i32 @llvm.aarch64.stxr.p0i64(i64 , i64*)
37 define i64 @test_udiv(i64 %x) {
38 ; CHECK-LABEL: @test_udiv(
40 ; CHECK-NEXT: [[CONST:%.*]] = bitcast i64 -9223372036317904832 to i64
41 ; CHECK-NEXT: [[CONST_MAT:%.*]] = add i64 [[CONST]], -64
42 ; CHECK-NEXT: [[BAR_0:%.*]] = call i64 @llvm.aarch64.udiv.i64(i64 [[CONST_MAT]], i64 [[X:%.*]])
43 ; CHECK-NEXT: [[BAR_1:%.*]] = call i64 @llvm.aarch64.udiv.i64(i64 [[CONST]], i64 [[X]])
44 ; CHECK-NEXT: [[CONST_MAT1:%.*]] = add i64 [[CONST]], 64
45 ; CHECK-NEXT: [[BAR_2:%.*]] = call i64 @llvm.aarch64.udiv.i64(i64 [[CONST_MAT1]], i64 [[X]])
46 ; CHECK-NEXT: [[CONST_MAT2:%.*]] = add i64 [[CONST]], 128
47 ; CHECK-NEXT: [[BAR_3:%.*]] = call i64 @llvm.aarch64.udiv.i64(i64 [[CONST_MAT2]], i64 [[X]])
48 ; CHECK-NEXT: [[RES_1:%.*]] = add i64 [[BAR_0]], [[BAR_1]]
49 ; CHECK-NEXT: [[RES_2:%.*]] = add i64 [[RES_1]], [[BAR_2]]
50 ; CHECK-NEXT: [[RES_3:%.*]] = add i64 [[RES_2]], [[BAR_3]]
51 ; CHECK-NEXT: ret i64 [[RES_3]]
54 %bar.0 = call i64 @llvm.aarch64.udiv.i64.i64(i64 -9223372036317904896, i64 %x)
55 %bar.1 = call i64 @llvm.aarch64.udiv.i64.i64(i64 -9223372036317904832, i64 %x)
56 %bar.2 = call i64 @llvm.aarch64.udiv.i64.i64(i64 -9223372036317904768, i64 %x)
57 %bar.3 = call i64 @llvm.aarch64.udiv.i64.i64(i64 -9223372036317904704, i64 %x)
58 %res.1 = add i64 %bar.0, %bar.1
59 %res.2 = add i64 %res.1, %bar.2
60 %res.3 = add i64 %res.2, %bar.3
64 declare i64 @llvm.aarch64.udiv.i64.i64(i64, i64)
66 define void @test_free_intrinsics(i64 %x, i8* %ptr) {
67 ; CHECK-LABEL: @test_free_intrinsics(
69 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 100000000032, i8* [[PTR:%.*]])
70 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 100000000064, i8* [[PTR]])
71 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 100000000128, i8* [[PTR]])
72 ; CHECK-NEXT: [[I:%.*]] = call {}* @llvm.invariant.start.p0i8(i64 100000000256, i8* [[PTR]])
73 ; CHECK-NEXT: call void @llvm.invariant.end.p0i8({}* [[I]], i64 100000000256, i8* [[PTR]])
74 ; CHECK-NEXT: ret void
77 call void @llvm.lifetime.start.p0i8(i64 100000000032, i8* %ptr)
78 call void @llvm.lifetime.start.p0i8(i64 100000000064, i8* %ptr)
79 call void @llvm.lifetime.end.p0i8(i64 100000000128, i8* %ptr)
80 %i = call {}* @llvm.invariant.start.p0i8(i64 100000000256, i8* %ptr)
81 call void @llvm.invariant.end.p0i8({}* %i, i64 100000000256, i8* %ptr)
85 declare void @llvm.lifetime.start.p0i8(i64, i8*)
86 declare void @llvm.lifetime.end.p0i8(i64, i8*)
88 declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture)
89 declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture)