1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3; PR2165
4
5define <1 x i64> @test1() {
6; CHECK-LABEL: @test1(
7; CHECK-NEXT:    ret <1 x i64> <i64 63>
8;
9  %A = bitcast i64 63 to <1 x i64>
10  ret <1 x i64> %A
11}
12
13; Ensure that a FP source operand isn't propagated to an icmp.
14
15@a = external global i16, align 1
16@b = external global i16, align 1
17
18define i1 @bad_icmp_constexpr_bitcast() {
19; CHECK-LABEL: @bad_icmp_constexpr_bitcast(
20; CHECK-NEXT:    ret i1 icmp eq (i32 ptrtoint (ptr @a to i32), i32 bitcast (float fadd (float bitcast (i32 ptrtoint (ptr @b to i32) to float), float 2.000000e+00) to i32))
21;
22  %cmp = icmp eq i32 ptrtoint (ptr @a to i32), bitcast (float fadd (float bitcast (i32 ptrtoint (ptr @b to i32) to float), float 2.0) to i32)
23  ret i1 %cmp
24}
25
26; Ensure that an integer source operand isn't propagated to a fcmp.
27
28@c = external global i16, align 1
29@d = external global i16, align 1
30
31define i1 @bad_fcmp_constexpr_bitcast() {
32; CHECK-LABEL: @bad_fcmp_constexpr_bitcast(
33; CHECK-NEXT:    ret i1 fcmp oeq (float bitcast (i32 ptrtoint (ptr @c to i32) to float), float bitcast (i32 add (i32 ptrtoint (ptr @d to i32), i32 2) to float))
34;
35  %cmp = fcmp oeq float bitcast (i32 ptrtoint (ptr @c to i32) to float), bitcast (i32 add (i32 ptrtoint (ptr @d to i32), i32 2) to float)
36  ret i1 %cmp
37}
38
39; Ensure that an "ordered and equal" fcmp of a ConstantExpr to itself is not folded, since the ConstantExpr may be a NaN.
40
41define i1 @fcmp_constexpr_oeq(float %conv) {
42; CHECK-LABEL: @fcmp_constexpr_oeq(
43; CHECK-NEXT:    ret i1 fcmp oeq (float bitcast (i32 ptrtoint (ptr @a to i32) to float), float bitcast (i32 ptrtoint (ptr @a to i32) to float))
44;
45  %cmp = fcmp oeq float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
46  ret i1 %cmp
47}
48
49; Ensure that an "unordered or not equal" fcmp of a ConstantExpr to itself is not folded, since the ConstantExpr may be a NaN.
50
51define i1 @fcmp_constexpr_une(float %conv) {
52; CHECK-LABEL: @fcmp_constexpr_une(
53; CHECK-NEXT:    ret i1 fcmp une (float bitcast (i32 ptrtoint (ptr @a to i32) to float), float bitcast (i32 ptrtoint (ptr @a to i32) to float))
54;
55  %cmp = fcmp une float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
56  ret i1 %cmp
57}
58
59define i1 @fcmp_constexpr_ueq(float %conv) {
60; CHECK-LABEL: @fcmp_constexpr_ueq(
61; CHECK-NEXT:    ret i1 true
62;
63  %cmp = fcmp ueq float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
64  ret i1 %cmp
65}
66
67define i1 @fcmp_constexpr_one(float %conv) {
68; CHECK-LABEL: @fcmp_constexpr_one(
69; CHECK-NEXT:    ret i1 false
70;
71  %cmp = fcmp one float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
72  ret i1 %cmp
73}
74
75%T = type { i8 }
76@G = external global %T
77
78define ptr @bitcast_to_gep() {
79; CHECK-LABEL: @bitcast_to_gep(
80; CHECK-NEXT:    ret ptr @G
81;
82  ret ptr @G
83}
84
85define ptr addrspace(1) @addrspacecast_to_gep() {
86; CHECK-LABEL: @addrspacecast_to_gep(
87; CHECK-NEXT:    ret ptr addrspace(1) addrspacecast (ptr @G to ptr addrspace(1))
88;
89  %p = addrspacecast ptr @G to ptr addrspace(1)
90  ret ptr addrspace(1) %p
91}
92