1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=bdce < %s | FileCheck %s
4 ; BDCE applied to integer vectors.
6 define <2 x i32> @test_basic(<2 x i32> %a, <2 x i32> %b) {
7 ; CHECK-LABEL: @test_basic(
8 ; CHECK-NEXT: [[A3:%.*]] = and <2 x i32> zeroinitializer, splat (i32 4)
9 ; CHECK-NEXT: [[B2:%.*]] = add <2 x i32> [[B:%.*]], splat (i32 1)
10 ; CHECK-NEXT: [[B3:%.*]] = and <2 x i32> [[B2]], splat (i32 8)
11 ; CHECK-NEXT: [[C:%.*]] = or <2 x i32> [[A3]], [[B3]]
12 ; CHECK-NEXT: [[D:%.*]] = ashr <2 x i32> [[C]], splat (i32 3)
13 ; CHECK-NEXT: ret <2 x i32> [[D]]
15 %a2 = add <2 x i32> %a, <i32 1, i32 1>
16 %a3 = and <2 x i32> %a2, <i32 4, i32 4>
17 %b2 = add <2 x i32> %b, <i32 1, i32 1>
18 %b3 = and <2 x i32> %b2, <i32 8, i32 8>
19 %c = or <2 x i32> %a3, %b3
20 %d = ashr <2 x i32> %c, <i32 3, i32 3>
24 ; Going vector -> scalar
25 define i32 @test_extractelement(<2 x i32> %a, <2 x i32> %b) {
26 ; CHECK-LABEL: @test_extractelement(
27 ; CHECK-NEXT: [[A3:%.*]] = and <2 x i32> zeroinitializer, splat (i32 4)
28 ; CHECK-NEXT: [[B2:%.*]] = add <2 x i32> [[B:%.*]], splat (i32 1)
29 ; CHECK-NEXT: [[B3:%.*]] = and <2 x i32> [[B2]], splat (i32 8)
30 ; CHECK-NEXT: [[C:%.*]] = or <2 x i32> [[A3]], [[B3]]
31 ; CHECK-NEXT: [[D:%.*]] = extractelement <2 x i32> [[C]], i32 0
32 ; CHECK-NEXT: [[E:%.*]] = ashr i32 [[D]], 3
33 ; CHECK-NEXT: ret i32 [[E]]
35 %a2 = add <2 x i32> %a, <i32 1, i32 1>
36 %a3 = and <2 x i32> %a2, <i32 4, i32 4>
37 %b2 = add <2 x i32> %b, <i32 1, i32 1>
38 %b3 = and <2 x i32> %b2, <i32 8, i32 8>
39 %c = or <2 x i32> %a3, %b3
40 %d = extractelement <2 x i32> %c, i32 0
45 ; Going scalar -> vector
46 define <2 x i32> @test_insertelement(i32 %a, i32 %b) {
47 ; CHECK-LABEL: @test_insertelement(
48 ; CHECK-NEXT: [[X3:%.*]] = and <2 x i32> zeroinitializer, splat (i32 4)
49 ; CHECK-NEXT: [[Y:%.*]] = insertelement <2 x i32> undef, i32 [[B:%.*]], i32 0
50 ; CHECK-NEXT: [[Y2:%.*]] = insertelement <2 x i32> [[Y]], i32 [[A:%.*]], i32 1
51 ; CHECK-NEXT: [[Y3:%.*]] = and <2 x i32> [[Y2]], splat (i32 8)
52 ; CHECK-NEXT: [[Z:%.*]] = or <2 x i32> [[X3]], [[Y3]]
53 ; CHECK-NEXT: [[U:%.*]] = ashr <2 x i32> [[Z]], splat (i32 3)
54 ; CHECK-NEXT: ret <2 x i32> [[U]]
56 %x = insertelement <2 x i32> undef, i32 %a, i32 0
57 %x2 = insertelement <2 x i32> %x, i32 %b, i32 1
58 %x3 = and <2 x i32> %x2, <i32 4, i32 4>
59 %y = insertelement <2 x i32> undef, i32 %b, i32 0
60 %y2 = insertelement <2 x i32> %y, i32 %a, i32 1
61 %y3 = and <2 x i32> %y2, <i32 8, i32 8>
62 %z = or <2 x i32> %x3, %y3
63 %u = ashr <2 x i32> %z, <i32 3, i32 3>
67 ; Some non-int vectors and conversions
68 define <2 x i32> @test_conversion(<2 x i32> %a) {
69 ; CHECK-LABEL: @test_conversion(
70 ; CHECK-NEXT: [[A2:%.*]] = add <2 x i32> [[A:%.*]], splat (i32 1)
71 ; CHECK-NEXT: [[A3:%.*]] = and <2 x i32> [[A2]], splat (i32 2)
72 ; CHECK-NEXT: [[X:%.*]] = uitofp <2 x i32> [[A3]] to <2 x double>
73 ; CHECK-NEXT: [[Y:%.*]] = fadd <2 x double> [[X]], splat (double 1.000000e+00)
74 ; CHECK-NEXT: [[Z:%.*]] = fptoui <2 x double> [[Y]] to <2 x i32>
75 ; CHECK-NEXT: [[U:%.*]] = ashr <2 x i32> [[Z]], splat (i32 3)
76 ; CHECK-NEXT: ret <2 x i32> [[U]]
78 %a2 = add <2 x i32> %a, <i32 1, i32 1>
79 %a3 = and <2 x i32> %a2, <i32 2, i32 2>
80 %x = uitofp <2 x i32> %a3 to <2 x double>
81 %y = fadd <2 x double> %x, <double 1.0, double 1.0>
82 %z = fptoui <2 x double> %y to <2 x i32>
83 %u = ashr <2 x i32> %z, <i32 3, i32 3>
87 ; Assumption invalidation (adapted from invalidate-assumptions.ll)
88 define <2 x i1> @test_assumption_invalidation(<2 x i1> %b, <2 x i8> %x) {
89 ; CHECK-LABEL: @test_assumption_invalidation(
90 ; CHECK-NEXT: [[LITTLE_NUMBER:%.*]] = zext <2 x i1> [[B:%.*]] to <2 x i8>
91 ; CHECK-NEXT: [[BIG_NUMBER:%.*]] = shl <2 x i8> zeroinitializer, splat (i8 1)
92 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[BIG_NUMBER]], [[LITTLE_NUMBER]]
93 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i8> [[SUB]] to <2 x i1>
94 ; CHECK-NEXT: ret <2 x i1> [[TRUNC]]
96 %setbit = or <2 x i8> %x, <i8 64, i8 64>
97 %little_number = zext <2 x i1> %b to <2 x i8>
98 %big_number = shl <2 x i8> %setbit, <i8 1, i8 1>
99 %sub = sub nuw <2 x i8> %big_number, %little_number
100 %trunc = trunc <2 x i8> %sub to <2 x i1>