1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S -data-layout="e-m:e-i64:64-f80:128-n8:16:32:64-S128" | FileCheck %s
4 @a = global [1000 x float] zeroinitializer, align 16
5 @b = global [1000 x float] zeroinitializer, align 16
7 define void @_Z3foov() {
8 ; CHECK-LABEL: @_Z3foov(
10 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
12 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_BODY:%.*]] ]
13 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I_0]], 1000
14 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP:%.*]]
15 ; CHECK: for.cond.cleanup:
16 ; CHECK-NEXT: ret void
18 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[I_0]] to i64
19 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [1000 x float], [1000 x float]* @a, i64 0, i64 [[TMP0]]
20 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds [1000 x float], [1000 x float]* @b, i64 0, i64 [[TMP0]]
21 ; CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[ARRAYIDX]], align 4
22 ; CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[ARRAYIDX2]], align 4
23 ; CHECK-NEXT: [[CMP_I:%.*]] = fcmp fast olt float [[TMP1]], [[TMP2]]
24 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[CMP_I]], float [[TMP2]], float [[TMP1]]
25 ; CHECK-NEXT: store float [[TMP3]], float* [[ARRAYIDX]], align 4
26 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_0]], 1
27 ; CHECK-NEXT: br label [[FOR_COND]]
32 for.cond: ; preds = %for.body, %entry
33 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
34 %cmp = icmp ult i32 %i.0, 1000
35 br i1 %cmp, label %for.body, label %for.cond.cleanup
37 for.cond.cleanup: ; preds = %for.cond
40 for.body: ; preds = %for.cond
41 %0 = zext i32 %i.0 to i64
42 %arrayidx = getelementptr inbounds [1000 x float], [1000 x float]* @a, i64 0, i64 %0
43 %arrayidx2 = getelementptr inbounds [1000 x float], [1000 x float]* @b, i64 0, i64 %0
44 %1 = load float, float* %arrayidx, align 4
45 %2 = load float, float* %arrayidx2, align 4
46 %cmp.i = fcmp fast olt float %1, %2
47 %__b.__a.i = select i1 %cmp.i, float* %arrayidx2, float* %arrayidx
48 %3 = bitcast float* %__b.__a.i to i32*
49 %4 = load i32, i32* %3, align 4
50 %5 = bitcast float* %arrayidx to i32*
51 store i32 %4, i32* %5, align 4
52 %inc = add nuw nsw i32 %i.0, 1
56 define i32 @store_bitcasted_load(i1 %cond, float* dereferenceable(4) %addr1, float* dereferenceable(4) %addr2) {
57 ; CHECK-LABEL: @store_bitcasted_load(
58 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float* [[ADDR1:%.*]], float* [[ADDR2:%.*]]
59 ; CHECK-NEXT: [[BC1:%.*]] = bitcast float* [[SEL]] to i32*
60 ; CHECK-NEXT: [[LD:%.*]] = load i32, i32* [[BC1]], align 4
61 ; CHECK-NEXT: ret i32 [[LD]]
63 %sel = select i1 %cond, float* %addr1, float* %addr2
64 %bc1 = bitcast float* %sel to i32*
65 %ld = load i32, i32* %bc1
69 define void @bitcasted_store(i1 %cond, float* %loadaddr1, float* %loadaddr2, float* %storeaddr) {
70 ; CHECK-LABEL: @bitcasted_store(
71 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float* [[LOADADDR1:%.*]], float* [[LOADADDR2:%.*]]
72 ; CHECK-NEXT: [[INT_LOAD_ADDR:%.*]] = bitcast float* [[SEL]] to i32*
73 ; CHECK-NEXT: [[LD:%.*]] = load i32, i32* [[INT_LOAD_ADDR]], align 4
74 ; CHECK-NEXT: [[INT_STORE_ADDR:%.*]] = bitcast float* [[STOREADDR:%.*]] to i32*
75 ; CHECK-NEXT: store i32 [[LD]], i32* [[INT_STORE_ADDR]], align 4
76 ; CHECK-NEXT: ret void
78 %sel = select i1 %cond, float* %loadaddr1, float* %loadaddr2
79 %int_load_addr = bitcast float* %sel to i32*
80 %ld = load i32, i32* %int_load_addr
81 %int_store_addr = bitcast float* %storeaddr to i32*
82 store i32 %ld, i32* %int_store_addr
86 define void @bitcasted_minmax_with_select_of_pointers(float* %loadaddr1, float* %loadaddr2, float* %storeaddr) {
87 ; CHECK-LABEL: @bitcasted_minmax_with_select_of_pointers(
88 ; CHECK-NEXT: [[LD1:%.*]] = load float, float* [[LOADADDR1:%.*]], align 4
89 ; CHECK-NEXT: [[LD2:%.*]] = load float, float* [[LOADADDR2:%.*]], align 4
90 ; CHECK-NEXT: [[COND:%.*]] = fcmp ogt float [[LD1]], [[LD2]]
91 ; CHECK-NEXT: [[LD3:%.*]] = select i1 [[COND]], float [[LD1]], float [[LD2]]
92 ; CHECK-NEXT: store float [[LD3]], float* [[STOREADDR:%.*]], align 4
93 ; CHECK-NEXT: ret void
95 %ld1 = load float, float* %loadaddr1, align 4
96 %ld2 = load float, float* %loadaddr2, align 4
97 %cond = fcmp ogt float %ld1, %ld2
98 %sel = select i1 %cond, float* %loadaddr1, float* %loadaddr2
99 %int_load_addr = bitcast float* %sel to i32*
100 %ld = load i32, i32* %int_load_addr, align 4
101 %int_store_addr = bitcast float* %storeaddr to i32*
102 store i32 %ld, i32* %int_store_addr, align 4