xref: /llvm-project/llvm/test/Transforms/InstSimplify/ConstProp/bitcast.ll (revision 38fffa630ee80163dc65e759392ad29798905679)
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> splat (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:    [[FADD:%.*]] = fadd float bitcast (i32 ptrtoint (ptr @b to i32) to float), 2.000000e+00
21; CHECK-NEXT:    [[BITCAST:%.*]] = bitcast float [[FADD]] to i32
22; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 ptrtoint (ptr @a to i32), [[BITCAST]]
23; CHECK-NEXT:    ret i1 [[CMP]]
24;
25  %fadd = fadd float bitcast (i32 ptrtoint (ptr @b to i32) to float), 2.0
26  %bitcast = bitcast float %fadd to i32
27  %cmp = icmp eq i32 ptrtoint (ptr @a to i32), %bitcast
28  ret i1 %cmp
29}
30
31; Ensure that an integer source operand isn't propagated to a fcmp.
32
33@c = external global i16, align 1
34@d = external global i16, align 1
35
36define i1 @bad_fcmp_constexpr_bitcast() {
37; CHECK-LABEL: @bad_fcmp_constexpr_bitcast(
38; CHECK-NEXT:    [[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)
39; CHECK-NEXT:    ret i1 [[CMP]]
40;
41  %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)
42  ret i1 %cmp
43}
44
45; Ensure that an "ordered and equal" fcmp of a ConstantExpr to itself is not folded, since the ConstantExpr may be a NaN.
46
47define i1 @fcmp_constexpr_oeq(float %conv) {
48; CHECK-LABEL: @fcmp_constexpr_oeq(
49; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
50; CHECK-NEXT:    ret i1 [[CMP]]
51;
52  %cmp = fcmp oeq float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
53  ret i1 %cmp
54}
55
56; Ensure that an "unordered or not equal" fcmp of a ConstantExpr to itself is not folded, since the ConstantExpr may be a NaN.
57
58define i1 @fcmp_constexpr_une(float %conv) {
59; CHECK-LABEL: @fcmp_constexpr_une(
60; CHECK-NEXT:    [[CMP:%.*]] = fcmp une float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
61; CHECK-NEXT:    ret i1 [[CMP]]
62;
63  %cmp = fcmp une 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_ueq(float %conv) {
68; CHECK-LABEL: @fcmp_constexpr_ueq(
69; CHECK-NEXT:    ret i1 true
70;
71  %cmp = fcmp ueq 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
75define i1 @fcmp_constexpr_one(float %conv) {
76; CHECK-LABEL: @fcmp_constexpr_one(
77; CHECK-NEXT:    ret i1 false
78;
79  %cmp = fcmp one float bitcast (i32 ptrtoint (ptr @a to i32) to float), bitcast (i32 ptrtoint (ptr @a to i32) to float)
80  ret i1 %cmp
81}
82
83%T = type { i8 }
84@G = external global %T
85
86define ptr @bitcast_to_gep() {
87; CHECK-LABEL: @bitcast_to_gep(
88; CHECK-NEXT:    ret ptr @G
89;
90  ret ptr @G
91}
92
93define ptr addrspace(1) @addrspacecast_to_gep() {
94; CHECK-LABEL: @addrspacecast_to_gep(
95; CHECK-NEXT:    ret ptr addrspace(1) addrspacecast (ptr @G to ptr addrspace(1))
96;
97  %p = addrspacecast ptr @G to ptr addrspace(1)
98  ret ptr addrspace(1) %p
99}
100