1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes='simplifycfg<sink-common-insts;switch-to-lookup>' < %s | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
define void @pr104567(i8 %x, ptr %f) {
; CHECK-LABEL: define void @pr104567(
; CHECK-SAME: i8 [[X:%.*]], ptr [[F:%.*]]) {
; CHECK-NEXT: [[START:.*:]]
; CHECK-NEXT: [[Y:%.*]] = alloca [1 x i8], align 1
; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 1, ptr nonnull [[Y]])
; CHECK-NEXT: [[SWITCH_OFFSET:%.*]] = add nsw i8 [[X]], 4
; CHECK-NEXT: store i8 [[SWITCH_OFFSET]], ptr [[Y]], align 1
; CHECK-NEXT: call void [[F]](ptr [[Y]])
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 1, ptr nonnull [[Y]])
; CHECK-NEXT: ret void
;
start:
%y = alloca [1 x i8], align 1
call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %y)
switch i8 %x, label %default.unreachable [
i8 0, label %bb4
i8 1, label %bb3
i8 2, label %bb2
]
default.unreachable:
unreachable
bb4:
store i8 4, ptr %y, align 1
br label %bb5
bb3:
store i8 5, ptr %y, align 1
br label %bb5
bb2:
store i8 6, ptr %y, align 1
br label %bb5
bb5:
call void %f(ptr %y)
call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %y)
ret void
}
define i64 @dont_make_div_variable(i64 noundef %x, i64 noundef %i) {
; CHECK-LABEL: define i64 @dont_make_div_variable(
; CHECK-SAME: i64 noundef [[X:%.*]], i64 noundef [[I:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: switch i64 [[I]], label %[[SW_DEFAULT:.*]] [
; CHECK-NEXT: i64 9, label %[[SW_BB:.*]]
; CHECK-NEXT: i64 10, label %[[SW_BB1:.*]]
; CHECK-NEXT: i64 11, label %[[SW_BB3:.*]]
; CHECK-NEXT: i64 12, label %[[SW_BB5:.*]]
; CHECK-NEXT: ]
; CHECK: [[SW_BB]]:
; CHECK-NEXT: [[DIV:%.*]] = udiv i64 [[X]], 9
; CHECK-NEXT: br label %[[RETURN:.*]]
; CHECK: [[SW_BB1]]:
; CHECK-NEXT: [[DIV2:%.*]] = udiv i64 [[X]], 10
; CHECK-NEXT: br label %[[RETURN]]
; CHECK: [[SW_BB3]]:
; CHECK-NEXT: [[DIV4:%.*]] = udiv i64 [[X]], 11
; CHECK-NEXT: br label %[[RETURN]]
; CHECK: [[SW_BB5]]:
; CHECK-NEXT: [[DIV7:%.*]] = udiv i64 [[X]], 12
; CHECK-NEXT: br label %[[RETURN]]
; CHECK: [[SW_DEFAULT]]:
; CHECK-NEXT: unreachable
; CHECK: [[RETURN]]:
; CHECK-NEXT: [[DIV6:%.*]] = phi i64 [ [[DIV7]], %[[SW_BB5]] ], [ [[DIV4]], %[[SW_BB3]] ], [ [[DIV2]], %[[SW_BB1]] ], [ [[DIV]], %[[SW_BB]] ]
; CHECK-NEXT: ret i64 [[DIV6]]
;
entry:
switch i64 %i, label %sw.default [
i64 9, label %sw.bb
i64 10, label %sw.bb1
i64 11, label %sw.bb3
i64 12, label %sw.bb5
]
sw.bb:
%div = udiv i64 %x, 9
br label %return
sw.bb1:
%div2 = udiv i64 %x, 10
br label %return
sw.bb3:
%div4 = udiv i64 %x, 11
br label %return
sw.bb5:
%div6 = udiv i64 %x, 12
br label %return
sw.default:
unreachable
return:
%retval.0 = phi i64 [ %div6, %sw.bb5 ], [ %div4, %sw.bb3 ], [ %div2, %sw.bb1 ], [ %div, %sw.bb ]
ret i64 %retval.0
}
define i64 @okay_to_make_div_variable(i64 noundef %x, i64 noundef %i) {
; CHECK-LABEL: define i64 @okay_to_make_div_variable(
; CHECK-SAME: i64 noundef [[X:%.*]], i64 noundef [[I:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub nsw i64 [[I]], 9
; CHECK-NEXT: [[SWITCH_OFFSET:%.*]] = add nsw i64 [[SWITCH_TABLEIDX]], 9
; CHECK-NEXT: [[DIV6:%.*]] = udiv i64 [[SWITCH_OFFSET]], [[X]]
; CHECK-NEXT: ret i64 [[DIV6]]
;
entry:
switch i64 %i, label %sw.default [
i64 9, label %sw.bb
i64 10, label %sw.bb1
i64 11, label %sw.bb3
i64 12, label %sw.bb5
]
sw.bb:
%div = udiv i64 9, %x
br label %return
sw.bb1:
%div2 = udiv i64 10, %x
br label %return
sw.bb3:
%div4 = udiv i64 11, %x
br label %return
sw.bb5:
%div6 = udiv i64 12, %x
br label %return
sw.default:
unreachable
return:
%retval.0 = phi i64 [ %div6, %sw.bb5 ], [ %div4, %sw.bb3 ], [ %div2, %sw.bb1 ], [ %div, %sw.bb ]
ret i64 %retval.0
}
|