two-shifts-by-sext.ll
4.59 KB
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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -O1 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-01
; RUN: opt -O2 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-02
; RUN: opt -O3 -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-03
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; int two_shifts_by_sext(int val, char len) {
; return (val << len) >> len;
; }
;
; int two_shifts_by_same_sext(int val, char len) {
; int wide_len = len;
; return (val << wide_len) >> wide_len;
; }
;
; void use_int32(int);
; int two_shifts_by_sext_with_extra_use(int val, char len) {
; use_int32(len);
; return (val << len) >> len;
; }
;
; int two_shifts_by_same_sext_with_extra_use(int val, char len) {
; int wide_len = len;
; use_int32(wide_len);
; return (val << wide_len) >> wide_len;
; }
define i32 @two_shifts_by_sext(i32 %val, i8 signext %len) {
; CHECK-LABEL: @two_shifts_by_sext(
; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[LEN:%.*]] to i32
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[VAL:%.*]], [[CONV]]
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[SHL]], [[CONV]]
; CHECK-NEXT: ret i32 [[SHR]]
;
%val.addr = alloca i32, align 4
%len.addr = alloca i8, align 1
store i32 %val, i32* %val.addr, align 4
store i8 %len, i8* %len.addr, align 1
%val.reloaded = load i32, i32* %val.addr, align 4
%len.reloaded.0 = load i8, i8* %len.addr, align 1
%conv = sext i8 %len.reloaded.0 to i32
%shl = shl i32 %val.reloaded, %conv
%len.reloaded.1 = load i8, i8* %len.addr, align 1
%conv1 = sext i8 %len.reloaded.1 to i32
%shr = ashr i32 %shl, %conv1
ret i32 %shr
}
define i32 @two_shifts_by_same_sext(i32 %val, i8 signext %len) {
; CHECK-LABEL: @two_shifts_by_same_sext(
; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[LEN:%.*]] to i32
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[VAL:%.*]], [[CONV]]
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[SHL]], [[CONV]]
; CHECK-NEXT: ret i32 [[SHR]]
;
%val.addr = alloca i32, align 4
%len.addr = alloca i8, align 1
%wide_len = alloca i32, align 4
store i32 %val, i32* %val.addr, align 4
store i8 %len, i8* %len.addr, align 1
%len.reloaded.0 = load i8, i8* %len.addr, align 1
%conv = sext i8 %len.reloaded.0 to i32
store i32 %conv, i32* %wide_len, align 4
%val.reloaded = load i32, i32* %val.addr, align 4
%len.reloaded.1 = load i32, i32* %wide_len, align 4
%shl = shl i32 %val.reloaded, %len.reloaded.1
%len.reloaded.2 = load i32, i32* %wide_len, align 4
%shr = ashr i32 %shl, %len.reloaded.2
ret i32 %shr
}
define i32 @two_shifts_by_sext_with_extra_use(i32 %val, i8 signext %len) {
; CHECK-LABEL: @two_shifts_by_sext_with_extra_use(
; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[LEN:%.*]] to i32
; CHECK-NEXT: call void @use_int32(i32 [[CONV]])
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[VAL:%.*]], [[CONV]]
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[SHL]], [[CONV]]
; CHECK-NEXT: ret i32 [[SHR]]
;
%val.addr = alloca i32, align 4
%len.addr = alloca i8, align 1
store i32 %val, i32* %val.addr, align 4
store i8 %len, i8* %len.addr, align 1
%len.reloaded.0 = load i8, i8* %len.addr, align 1
%conv = sext i8 %len.reloaded.0 to i32
call void @use_int32(i32 %conv)
%val.reloaded = load i32, i32* %val.addr, align 4
%len.reloaded.1 = load i8, i8* %len.addr, align 1
%conv1 = sext i8 %len.reloaded.1 to i32
%shl = shl i32 %val.reloaded, %conv1
%len.reloaded.2 = load i8, i8* %len.addr, align 1
%conv2 = sext i8 %len.reloaded.2 to i32
%shr = ashr i32 %shl, %conv2
ret i32 %shr
}
declare void @use_int32(i32)
define i32 @two_shifts_by_same_sext_with_extra_use(i32 %val, i8 signext %len) {
; CHECK-LABEL: @two_shifts_by_same_sext_with_extra_use(
; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[LEN:%.*]] to i32
; CHECK-NEXT: call void @use_int32(i32 [[CONV]])
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[VAL:%.*]], [[CONV]]
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[SHL]], [[CONV]]
; CHECK-NEXT: ret i32 [[SHR]]
;
%val.addr = alloca i32, align 4
%len.addr = alloca i8, align 1
%wide_len = alloca i32, align 4
store i32 %val, i32* %val.addr, align 4
store i8 %len, i8* %len.addr, align 1
%len.reloaded.0 = load i8, i8* %len.addr, align 1
%conv = sext i8 %len.reloaded.0 to i32
store i32 %conv, i32* %wide_len, align 4
%val.reloaded = load i32, i32* %wide_len, align 4
call void @use_int32(i32 %val.reloaded)
%len.reloaded.1 = load i32, i32* %val.addr, align 4
%len.reloaded.2 = load i32, i32* %wide_len, align 4
%shl = shl i32 %len.reloaded.1, %len.reloaded.2
%wide_len.reloaded = load i32, i32* %wide_len, align 4
%shr = ashr i32 %shl, %wide_len.reloaded
ret i32 %shr
}