1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -mtriple=x86_64-- -expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s
3 ; RUN: opt -S -mtriple=x86_64-- -passes=expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s
5 define void @test(ptr %ptr, ptr %out) nounwind {
7 ; CHECK-NEXT: _udiv-special-cases:
8 ; CHECK-NEXT: [[A:%.*]] = load i129, ptr [[PTR:%.*]], align 16
9 ; CHECK-NEXT: [[TMP0:%.*]] = freeze i129 3
10 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i129 [[A]]
11 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i129 [[TMP0]], 0
12 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i129 [[TMP1]], 0
13 ; CHECK-NEXT: [[TMP4:%.*]] = or i1 [[TMP2]], [[TMP3]]
14 ; CHECK-NEXT: [[TMP5:%.*]] = call i129 @llvm.ctlz.i129(i129 [[TMP0]], i1 true)
15 ; CHECK-NEXT: [[TMP6:%.*]] = call i129 @llvm.ctlz.i129(i129 [[TMP1]], i1 true)
16 ; CHECK-NEXT: [[TMP7:%.*]] = sub i129 [[TMP5]], [[TMP6]]
17 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i129 [[TMP7]], 128
18 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP4]], i1 true, i1 [[TMP8]]
19 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i129 [[TMP7]], 128
20 ; CHECK-NEXT: [[TMP11:%.*]] = select i1 [[TMP9]], i129 0, i129 [[TMP1]]
21 ; CHECK-NEXT: [[TMP12:%.*]] = select i1 [[TMP9]], i1 true, i1 [[TMP10]]
22 ; CHECK-NEXT: br i1 [[TMP12]], label [[UDIV_END:%.*]], label [[UDIV_BB1:%.*]]
23 ; CHECK: udiv-loop-exit:
24 ; CHECK-NEXT: [[TMP13:%.*]] = phi i129 [ 0, [[UDIV_BB1]] ], [ [[TMP28:%.*]], [[UDIV_DO_WHILE:%.*]] ]
25 ; CHECK-NEXT: [[TMP14:%.*]] = phi i129 [ [[TMP37:%.*]], [[UDIV_BB1]] ], [ [[TMP25:%.*]], [[UDIV_DO_WHILE]] ]
26 ; CHECK-NEXT: [[TMP15:%.*]] = shl i129 [[TMP14]], 1
27 ; CHECK-NEXT: [[TMP16:%.*]] = or i129 [[TMP13]], [[TMP15]]
28 ; CHECK-NEXT: br label [[UDIV_END]]
29 ; CHECK: udiv-do-while:
30 ; CHECK-NEXT: [[TMP17:%.*]] = phi i129 [ 0, [[UDIV_PREHEADER:%.*]] ], [ [[TMP28]], [[UDIV_DO_WHILE]] ]
31 ; CHECK-NEXT: [[TMP18:%.*]] = phi i129 [ [[TMP35:%.*]], [[UDIV_PREHEADER]] ], [ [[TMP31:%.*]], [[UDIV_DO_WHILE]] ]
32 ; CHECK-NEXT: [[TMP19:%.*]] = phi i129 [ [[TMP33:%.*]], [[UDIV_PREHEADER]] ], [ [[TMP30:%.*]], [[UDIV_DO_WHILE]] ]
33 ; CHECK-NEXT: [[TMP20:%.*]] = phi i129 [ [[TMP37]], [[UDIV_PREHEADER]] ], [ [[TMP25]], [[UDIV_DO_WHILE]] ]
34 ; CHECK-NEXT: [[TMP21:%.*]] = shl i129 [[TMP19]], 1
35 ; CHECK-NEXT: [[TMP22:%.*]] = lshr i129 [[TMP20]], 128
36 ; CHECK-NEXT: [[TMP23:%.*]] = or i129 [[TMP21]], [[TMP22]]
37 ; CHECK-NEXT: [[TMP24:%.*]] = shl i129 [[TMP20]], 1
38 ; CHECK-NEXT: [[TMP25]] = or i129 [[TMP17]], [[TMP24]]
39 ; CHECK-NEXT: [[TMP26:%.*]] = sub i129 [[TMP34:%.*]], [[TMP23]]
40 ; CHECK-NEXT: [[TMP27:%.*]] = ashr i129 [[TMP26]], 128
41 ; CHECK-NEXT: [[TMP28]] = and i129 [[TMP27]], 1
42 ; CHECK-NEXT: [[TMP29:%.*]] = and i129 [[TMP27]], [[TMP0]]
43 ; CHECK-NEXT: [[TMP30]] = sub i129 [[TMP23]], [[TMP29]]
44 ; CHECK-NEXT: [[TMP31]] = add i129 [[TMP18]], -1
45 ; CHECK-NEXT: [[TMP32:%.*]] = icmp eq i129 [[TMP31]], 0
46 ; CHECK-NEXT: br i1 [[TMP32]], label [[UDIV_LOOP_EXIT:%.*]], label [[UDIV_DO_WHILE]]
47 ; CHECK: udiv-preheader:
48 ; CHECK-NEXT: [[TMP33]] = lshr i129 [[TMP1]], [[TMP35]]
49 ; CHECK-NEXT: [[TMP34]] = add i129 [[TMP0]], -1
50 ; CHECK-NEXT: br label [[UDIV_DO_WHILE]]
52 ; CHECK-NEXT: [[TMP35]] = add i129 [[TMP7]], 1
53 ; CHECK-NEXT: [[TMP36:%.*]] = sub i129 128, [[TMP7]]
54 ; CHECK-NEXT: [[TMP37]] = shl i129 [[TMP1]], [[TMP36]]
55 ; CHECK-NEXT: [[TMP38:%.*]] = icmp eq i129 [[TMP35]], 0
56 ; CHECK-NEXT: br i1 [[TMP38]], label [[UDIV_LOOP_EXIT]], label [[UDIV_PREHEADER]]
58 ; CHECK-NEXT: [[TMP39:%.*]] = phi i129 [ [[TMP16]], [[UDIV_LOOP_EXIT]] ], [ [[TMP11]], [[_UDIV_SPECIAL_CASES:%.*]] ]
59 ; CHECK-NEXT: store i129 [[TMP39]], ptr [[OUT:%.*]], align 16
60 ; CHECK-NEXT: ret void
62 %a = load i129, ptr %ptr
63 %res = udiv i129 %a, 3
64 store i129 %res, ptr %out