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
|
; RUN: opt %s -nacl-promote-i1-ops -S | FileCheck %s
; Test that the PromoteI1Ops pass expands out i1 loads/stores and i1
; comparison and arithmetic operations, with the exception of "and",
; "or" and "xor".
; i1 loads and stores are converted to i8 load and stores with
; explicit casts.
define i1 @load(i1* %ptr) {
%val = load i1* %ptr
ret i1 %val
}
; CHECK: define i1 @load
; CHECK-NEXT: %ptr.i8ptr = bitcast i1* %ptr to i8*
; CHECK-NEXT: %val.pre_trunc = load i8* %ptr.i8ptr
; CHECK-NEXT: %val = trunc i8 %val.pre_trunc to i1
define void @store(i1 %val, i1* %ptr) {
store i1 %val, i1* %ptr
ret void
}
; CHECK: define void @store
; CHECK-NEXT: %ptr.i8ptr = bitcast i1* %ptr to i8*
; CHECK-NEXT: %val.expand_i1_val = zext i1 %val to i8
; CHECK-NEXT: store i8 %val.expand_i1_val, i8* %ptr.i8ptr
; i1 arithmetic and comparisons are converted to their i8 equivalents
; with explicit casts.
define i1 @add(i1 %x, i1 %y) {
%result = add i1 %x, %y
ret i1 %result
}
; CHECK: define i1 @add
; CHECK-NEXT: %x.expand_i1_val = zext i1 %x to i8
; CHECK-NEXT: %y.expand_i1_val = zext i1 %y to i8
; CHECK-NEXT: %result.pre_trunc = add i8 %x.expand_i1_val, %y.expand_i1_val
; CHECK-NEXT: %result = trunc i8 %result.pre_trunc to i1
define i1 @compare(i1 %x, i1 %y) {
%result = icmp slt i1 %x, %y
ret i1 %result
}
; CHECK: define i1 @compare
; CHECK-NEXT: %x.expand_i1_val = sext i1 %x to i8
; CHECK-NEXT: %y.expand_i1_val = sext i1 %y to i8
; CHECK-NEXT: %result = icmp slt i8 %x.expand_i1_val, %y.expand_i1_val
; Non-shift bitwise operations should not be modified.
define void @bitwise_ops(i1 %x, i1 %y) {
%and = and i1 %x, %y
%or = or i1 %x, %y
%xor = xor i1 %x, %y
ret void
}
; CHECK: define void @bitwise_ops
; CHECK-NEXT: %and = and i1 %x, %y
; CHECK-NEXT: %or = or i1 %x, %y
; CHECK-NEXT: %xor = xor i1 %x, %y
define void @unchanged_cases(i32 %x, i32 %y, i32* %ptr) {
%add = add i32 %x, %y
%cmp = icmp slt i32 %x, %y
%val = load i32* %ptr
store i32 %x, i32* %ptr
ret void
}
; CHECK: define void @unchanged_cases
; CHECK-NEXT: %add = add i32 %x, %y
; CHECK-NEXT: %cmp = icmp slt i32 %x, %y
; CHECK-NEXT: %val = load i32* %ptr
; CHECK-NEXT: store i32 %x, i32* %ptr
|