1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
3target datalayout = "p:32:32"
4
5define i1 @test1(i1 %V) {
6; CHECK-LABEL: @test1(
7; CHECK-NEXT:  entry:
8; CHECK-NEXT:    ret i1 [[V:%.*]]
9;
10entry:
11  %Z = zext i1 %V to i32
12  %T = trunc i32 %Z to i1
13  ret i1 %T
14}
15
16define i8* @test2(i8* %V) {
17; CHECK-LABEL: @test2(
18; CHECK-NEXT:  entry:
19; CHECK-NEXT:    ret i8* [[V:%.*]]
20;
21entry:
22  %BC1 = bitcast i8* %V to i32*
23  %BC2 = bitcast i32* %BC1 to i8*
24  ret i8* %BC2
25}
26
27define i8* @test3(i8* %V) {
28; CHECK-LABEL: @test3(
29; CHECK-NEXT:  entry:
30; CHECK-NEXT:    ret i8* [[V:%.*]]
31;
32entry:
33  %BC = bitcast i8* %V to i8*
34  ret i8* %BC
35}
36
37define i32 @test4() {
38; CHECK-LABEL: @test4(
39; CHECK-NEXT:    ret i32 4
40;
41  %alloca = alloca i32, align 4                                     ; alloca + 0
42  %gep = getelementptr inbounds i32, i32* %alloca, i32 1            ; alloca + 4
43  %bc = bitcast i32* %gep to [4 x i8]*                              ; alloca + 4
44  %pti = ptrtoint i32* %alloca to i32                               ; alloca
45  %sub = sub i32 0, %pti                                            ; -alloca
46  %add = getelementptr [4 x i8], [4 x i8]* %bc, i32 0, i32 %sub     ; alloca + 4 - alloca == 4
47  %add_to_int = ptrtoint i8* %add to i32                            ; 4
48  ret i32 %add_to_int                                               ; 4
49}
50
51define i32 @test5() {
52; CHECK-LABEL: @test5(
53; CHECK-NEXT:    ret i32 3
54;
55  %alloca = alloca i32, align 4                                     ; alloca + 0
56  %gep = getelementptr inbounds i32, i32* %alloca, i32 1            ; alloca + 4
57  %bc = bitcast i32* %gep to [4 x i8]*                              ; alloca + 4
58  %pti = ptrtoint i32* %alloca to i32                               ; alloca
59  %sub = xor i32 %pti, -1                                           ; ~alloca
60  %add = getelementptr [4 x i8], [4 x i8]* %bc, i32 0, i32 %sub     ; alloca + 4 - alloca - 1 == 3
61  %add_to_int = ptrtoint i8* %add to i32                            ; 4
62  ret i32 %add_to_int                                               ; 4
63}
64