[InstCombine] (mul nsw 1, INT_MIN) != (shl nsw 1, 31)
[oota-llvm.git] / test / Transforms / InstCombine / memset_chk-1.ll
1 ; Test lib call simplification of __memset_chk calls with various values
2 ; for dstlen and len.
3 ;
4 ; RUN: opt < %s -instcombine -S | FileCheck %s
5 ; rdar://7719085
6
7 target 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.T = type { [100 x i32], [100 x i32], [1024 x i8] }
10 @t = common global %struct.T zeroinitializer
11
12 ; Check cases where dstlen >= len.
13
14 define i8* @test_simplify1() {
15 ; CHECK-LABEL: @test_simplify1(
16   %dst = bitcast %struct.T* @t to i8*
17
18 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
19 ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
20   %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 1824)
21   ret i8* %ret
22 }
23
24 define i8* @test_simplify2() {
25 ; CHECK-LABEL: @test_simplify2(
26   %dst = bitcast %struct.T* @t to i8*
27
28 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
29 ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
30   %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 3648)
31   ret i8* %ret
32 }
33
34 define i8* @test_simplify3() {
35 ; CHECK-LABEL: @test_simplify3(
36   %dst = bitcast %struct.T* @t to i8*
37
38 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
39 ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
40   %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 -1)
41   ret i8* %ret
42 }
43
44 ; Check cases where dstlen < len.
45
46 define i8* @test_no_simplify1() {
47 ; CHECK-LABEL: @test_no_simplify1(
48   %dst = bitcast %struct.T* @t to i8*
49
50 ; CHECK-NEXT: %ret = call i8* @__memset_chk(i8* bitcast (%struct.T* @t to i8*), i32 0, i64 1824, i64 400)
51 ; CHECK-NEXT: ret i8* %ret
52   %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 400)
53   ret i8* %ret
54 }
55
56 define i8* @test_no_simplify2() {
57 ; CHECK-LABEL: @test_no_simplify2(
58   %dst = bitcast %struct.T* @t to i8*
59
60 ; CHECK-NEXT: %ret = call i8* @__memset_chk(i8* bitcast (%struct.T* @t to i8*), i32 0, i64 1824, i64 0)
61 ; CHECK-NEXT: ret i8* %ret
62   %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 0)
63   ret i8* %ret
64 }
65
66 declare i8* @__memset_chk(i8*, i32, i64, i64)