1 ; RUN: opt -loop-load-elim -S < %s | FileCheck %s
3 ; Don't crash if the store and the load use different types.
5 ; for (unsigned i = 0; i < 100; i++) {
7 ; C[i] = ((float*)A)[i] * 2;
10 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
13 define void @f(i32* noalias %A, i32* noalias %B, i32* noalias %C, i64 %N) {
18 for.body: ; preds = %for.body, %entry
19 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
20 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
22 %Aidx_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
23 %Bidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
24 %Cidx = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
25 %Aidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
26 %Aidx.float = bitcast i32* %Aidx to float*
28 %b = load i32, i32* %Bidx, align 4
30 store i32 %a_p1, i32* %Aidx_next, align 4
32 ; CHECK: %a = load float, float* %Aidx.float, align 4
33 %a = load float, float* %Aidx.float, align 4
34 ; CHECK-NEXT: %c = fmul float %a, 2.0
35 %c = fmul float %a, 2.0
36 %c.int = fptosi float %c to i32
37 store i32 %c.int, i32* %Cidx, align 4
39 %exitcond = icmp eq i64 %indvars.iv.next, %N
40 br i1 %exitcond, label %for.end, label %for.body
42 for.end: ; preds = %for.body
46 ; Don't crash if the store and the load use different types.
48 ; for (unsigned i = 0; i < 100; i++) {
51 ; C[i] = ((float*)A)[i] * 2;
55 define void @f2(i32* noalias %A, i32* noalias %B, i32* noalias %C, i64 %N) {
60 for.body: ; preds = %for.body, %entry
61 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
62 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
64 %Aidx_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
65 %Bidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
66 %Cidx = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
67 %Aidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
68 %Aidx.float = bitcast i32* %Aidx to float*
70 %b = load i32, i32* %Bidx, align 4
72 store i32 %a_p2, i32* %Aidx_next, align 4
75 store i32 %a_p3, i32* %Aidx_next, align 4
77 ; CHECK: %a = load float, float* %Aidx.float, align 4
78 %a = load float, float* %Aidx.float, align 4
79 ; CHECK-NEXT: %c = fmul float %a, 2.0
80 %c = fmul float %a, 2.0
81 %c.int = fptosi float %c to i32
82 store i32 %c.int, i32* %Cidx, align 4
84 %exitcond = icmp eq i64 %indvars.iv.next, %N
85 br i1 %exitcond, label %for.end, label %for.body
87 for.end: ; preds = %for.body