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