1 ; RUN: opt -S -instcombine < %s | FileCheck %s 2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32" 3 target triple = "i386-apple-darwin10.0.0" 4 5 ; CHECK: define void @fu1 6 define void @fu1(i32 %parm) nounwind ssp { 7 %1 = alloca i32, align 4 8 ; CHECK: alloca double* 9 %ptr = alloca double*, align 4 10 store i32 %parm, i32* %1, align 4 11 store double* null, double** %ptr, align 4 12 %2 = load i32* %1, align 4 13 %3 = icmp ne i32 %2, 0 14 br i1 %3, label %4, label %10 15 16 ; <label>:4 ; preds = %0 17 %5 = load i32* %1, align 4 18 %6 = mul nsw i32 %5, 8 19 ; With "nsw", the alloca and its bitcast can be fused: 20 %7 = add nsw i32 %6, 2048 21 ; CHECK: alloca double 22 %8 = alloca i8, i32 %7 23 %9 = bitcast i8* %8 to double* 24 ; CHECK-NEXT: store double* 25 store double* %9, double** %ptr, align 4 26 br label %10 27 ; <label>:10 ; preds = %4, %0 28 %11 = load double** %ptr, align 4 29 call void @bar(double* %11) 30 ; CHECK: ret 31 ret void 32 } 33 34 declare void @bar(double*) 35 36 ; CHECK: define void @fu2 37 define void @fu2(i32 %parm) nounwind ssp { 38 %1 = alloca i32, align 4 39 %ptr = alloca double*, align 4 40 store i32 %parm, i32* %1, align 4 41 store double* null, double** %ptr, align 4 42 %2 = load i32* %1, align 4 43 %3 = icmp ne i32 %2, 0 44 br i1 %3, label %4, label %10 45 46 ; <label>:4 ; preds = %0 47 %5 = load i32* %1, align 4 48 %6 = mul nsw i32 %5, 8 49 ; Without "nsw", the alloca and its bitcast cannot be fused: 50 %7 = add i32 %6, 2048 51 ; CHECK: alloca i8 52 %8 = alloca i8, i32 %7 53 ; CHECK-NEXT: bitcast i8* 54 %9 = bitcast i8* %8 to double* 55 store double* %9, double** %ptr, align 4 56 br label %10 57 58 ; <label>:10 ; preds = %4, %0 59 %11 = load double** %ptr, align 4 60 call void @bar(double* %11) 61 ret void 62 } 63 64