xref: /llvm-project/llvm/test/Transforms/InstCombine/bitcast-store.ll (revision 32a4566fbb43f7195fd51fbe453b980897cec3fc)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2; RUN: opt -S -passes=instcombine < %s | FileCheck %s
3
4; Instcombine should preserve metadata and alignment while
5; folding a bitcast into a store.
6
7target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
8
9%struct.A = type { ptr }
10
11@G = external constant [5 x ptr]
12
13define void @foo(i32 %x, ptr %p) nounwind {
14; CHECK-LABEL: define void @foo
15; CHECK-SAME: (i32 [[X:%.*]], ptr [[P:%.*]]) #[[ATTR0:[0-9]+]] {
16; CHECK-NEXT:  entry:
17; CHECK-NEXT:    store i32 [[X]], ptr [[P]], align 16, !noalias !0, !llvm.access.group [[ACC_GRP3:![0-9]+]]
18; CHECK-NEXT:    ret void
19;
20entry:
21  %x.cast = bitcast i32 %x to float
22  store float %x.cast, ptr %p, align 16, !noalias !0, !llvm.access.group !3
23  ret void
24}
25
26; Check instcombine doesn't try and fold the following bitcast into the store.
27; This transformation would not be safe since we would need to use addrspacecast
28; and addrspacecast is not guaranteed to be a no-op cast.
29
30define void @bar(ptr addrspace(1) %a, ptr %b) nounwind {
31; CHECK-LABEL: define void @bar
32; CHECK-SAME: (ptr addrspace(1) [[A:%.*]], ptr [[B:%.*]]) #[[ATTR0]] {
33; CHECK-NEXT:  entry:
34; CHECK-NEXT:    store ptr addrspace(1) [[A]], ptr [[B]], align 8
35; CHECK-NEXT:    ret void
36;
37entry:
38  store ptr addrspace(1) %a, ptr %b
39  ret void
40}
41
42; Check that we don't combine the bitcast into the store. This would create a
43; bitcast of the swifterror which is invalid.
44
45%swift.error = type opaque
46define void @swifterror_store(ptr %x, ptr swifterror %err) {
47; CHECK-LABEL: define void @swifterror_store
48; CHECK-SAME: (ptr [[X:%.*]], ptr swifterror [[ERR:%.*]]) {
49; CHECK-NEXT:  entry:
50; CHECK-NEXT:    store ptr [[X]], ptr [[ERR]], align 8
51; CHECK-NEXT:    ret void
52;
53entry:
54  store ptr %x, ptr %err
55  ret void
56}
57
58define void @ppcf128_ones_store(ptr %dest) {
59; CHECK-LABEL: define void @ppcf128_ones_store
60; CHECK-SAME: (ptr [[DEST:%.*]]) {
61; CHECK-NEXT:  entry:
62; CHECK-NEXT:    store ppc_fp128 0xMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, ptr [[DEST]], align 16
63; CHECK-NEXT:    ret void
64;
65entry:
66  %int = or i128 0, 340282366920938463463374607431768211455 ; 128 ones
67  %val = bitcast i128 %int to ppc_fp128
68  store ppc_fp128 %val, ptr %dest, align 16
69  ret void
70}
71
72!0 = !{!1}
73!1 = !{!1, !2}
74!2 = !{!2}
75!3 = !{}
76