1; ModuleID = 'test1.c' 2; RUN: opt -S -instcombine < %s | FileCheck %s 3target triple = "x86_64-apple-macosx10.6.6" 4 5define zeroext i16 @foo1(i32 %on_off) nounwind uwtable ssp { 6entry: 7 %on_off.addr = alloca i32, align 4 8 %a = alloca i32, align 4 9 store i32 %on_off, i32* %on_off.addr, align 4 10 %tmp = load i32, i32* %on_off.addr, align 4 11 %sub = sub i32 1, %tmp 12; CHECK-NOT: mul i32 13 %mul = mul i32 %sub, -2 14; CHECK: shl 15; CHECK-NEXT: add 16 store i32 %mul, i32* %a, align 4 17 %tmp1 = load i32, i32* %a, align 4 18 %conv = trunc i32 %tmp1 to i16 19 ret i16 %conv 20} 21 22define zeroext i16 @foo2(i32 %on_off, i32 %q) nounwind uwtable ssp { 23entry: 24 %on_off.addr = alloca i32, align 4 25 %q.addr = alloca i32, align 4 26 %a = alloca i32, align 4 27 store i32 %on_off, i32* %on_off.addr, align 4 28 store i32 %q, i32* %q.addr, align 4 29 %tmp = load i32, i32* %q.addr, align 4 30 %tmp1 = load i32, i32* %on_off.addr, align 4 31 %sub = sub i32 %tmp, %tmp1 32; CHECK-NOT: mul i32 33 %mul = mul i32 %sub, -4 34; CHECK: sub i32 35; CHECK-NEXT: shl 36 store i32 %mul, i32* %a, align 4 37 %tmp2 = load i32, i32* %a, align 4 38 %conv = trunc i32 %tmp2 to i16 39 ret i16 %conv 40} 41 42define zeroext i16 @foo3(i32 %on_off) nounwind uwtable ssp { 43entry: 44 %on_off.addr = alloca i32, align 4 45 %a = alloca i32, align 4 46 store i32 %on_off, i32* %on_off.addr, align 4 47 %tmp = load i32, i32* %on_off.addr, align 4 48 %sub = sub i32 7, %tmp 49; CHECK-NOT: mul i32 50 %mul = mul i32 %sub, -4 51; CHECK: shl 52; CHECK-NEXT: add 53 store i32 %mul, i32* %a, align 4 54 %tmp1 = load i32, i32* %a, align 4 55 %conv = trunc i32 %tmp1 to i16 56 ret i16 %conv 57} 58