blob: 420cb4a1ff7781a9c4a6256825509a6938e4fc0d [file] [log] [blame]
Reid Spencer6c38f0b2006-11-27 01:05:10 +00001; Tests to make sure elimination of casts is working correctly
Edward O'Callaghan484b6c22009-10-12 06:14:06 +00002; RUN: opt < %s -instcombine -S | FileCheck %s
Reid Spencer6c38f0b2006-11-27 01:05:10 +00003
Tanya Lattner5640bd12008-03-01 09:15:35 +00004define i64 @test_sext_zext(i16 %A) {
5 %c1 = zext i16 %A to i32 ; <i32> [#uses=1]
6 %c2 = sext i32 %c1 to i64 ; <i64> [#uses=1]
7 ret i64 %c2
Edward O'Callaghan484b6c22009-10-12 06:14:06 +00008CHECK-NOT: %c1
9CHECK: %c2 = zext i16 %A to i64
10CHECK: ret i64 %c2
Reid Spencer6c38f0b2006-11-27 01:05:10 +000011}
Tanya Lattner5640bd12008-03-01 09:15:35 +000012
Chris Lattner24f31a02009-02-17 20:47:23 +000013; PR3599
14define i32 @test2(i64 %tmp) nounwind readnone {
15entry:
16 %tmp5 = trunc i64 %tmp to i8 ; <i8> [#uses=1]
17 %tmp7 = lshr i64 %tmp, 8 ; <i64> [#uses=1]
18 %tmp8 = trunc i64 %tmp7 to i8 ; <i8> [#uses=1]
19 %tmp10 = lshr i64 %tmp, 16 ; <i64> [#uses=1]
20 %tmp11 = trunc i64 %tmp10 to i8 ; <i8> [#uses=1]
21 %tmp13 = lshr i64 %tmp, 24 ; <i64> [#uses=1]
22 %tmp14 = trunc i64 %tmp13 to i8 ; <i8> [#uses=1]
23 %tmp1 = zext i8 %tmp5 to i32 ; <i32> [#uses=1]
24 %tmp2 = zext i8 %tmp8 to i32 ; <i32> [#uses=1]
25 %tmp3 = shl i32 %tmp2, 8 ; <i32> [#uses=1]
26 %tmp4 = zext i8 %tmp11 to i32 ; <i32> [#uses=1]
27 %tmp6 = shl i32 %tmp4, 16 ; <i32> [#uses=1]
28 %tmp9 = zext i8 %tmp14 to i32 ; <i32> [#uses=1]
29 %tmp12 = shl i32 %tmp9, 24 ; <i32> [#uses=1]
30 %tmp15 = or i32 %tmp12, %tmp1 ; <i32> [#uses=1]
31 %tmp16 = or i32 %tmp15, %tmp6 ; <i32> [#uses=1]
32 %tmp17 = or i32 %tmp16, %tmp3 ; <i32> [#uses=1]
33 ret i32 %tmp17
Edward O'Callaghan484b6c22009-10-12 06:14:06 +000034CHECK: ret i1 true
Chris Lattner24f31a02009-02-17 20:47:23 +000035}
36