1; XFAIL: *
2; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3; RUN: opt < %s -mergeicmps -verify-dom-info -mtriple=x86_64-unknown-unknown -S | FileCheck %s
4
5; This is a more involved test: clang generates this weird pattern for
6; tuple<uint8_t, uint8_t, uint8_t, uint8_t>. Right now we skip the entry block
7; (which defines the base pointer for other blocks) and the last one (which
8; does not have the expected structure). Only middle blocks (bytes [1,2]) are
9; merged.
10
11%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
12%"struct.std::_Tuple_impl" = type { %"struct.std::_Tuple_impl.0", %"struct.std::_Head_base.6" }
13%"struct.std::_Tuple_impl.0" = type { %"struct.std::_Tuple_impl.1", %"struct.std::_Head_base.5" }
14%"struct.std::_Tuple_impl.1" = type { %"struct.std::_Tuple_impl.2", %"struct.std::_Head_base.4" }
15%"struct.std::_Tuple_impl.2" = type { %"struct.std::_Head_base" }
16%"struct.std::_Head_base" = type { i8 }
17%"struct.std::_Head_base.4" = type { i8 }
18%"struct.std::_Head_base.5" = type { i8 }
19%"struct.std::_Head_base.6" = type { i8 }
20
21define zeroext i1 @opeq(
22; CHECK-LABEL: @opeq(
23;
24; These 2 instructions are split. Then we can merge 3 bytes, instead of 2.
25; CHECK:         br label [[LAND_ELEM0:%.*]]
26; CHECK:       land.elem1:
27; CHECK-NEXT:    [[A_ELEM1_ADDR:%.*]] = getelementptr inbounds i8, i8* %a.base, i64 1
28; CHECK-NEXT:    [[B_ELEM1_ADDR:%.*]] = getelementptr inbounds i8, i8* %b.base, i64 1
29; CHECK-NEXT:    [[MEMCMP:%.*]] = call i32 @memcmp(i8* [[A_ELEM1_ADDR]], i8* [[B_ELEM1_ADDR]], i64 3)
30; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[MEMCMP]], 0
31; CHECK-NEXT:    br label [[OPEQ_EXIT:%.*]]
32; CHECK:       land.elem0:
33; CHECK:         [[A_BASE:%.*]] = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* [[A:%.*]], i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
34; CHECK:         [[B_BASE:%.*]] = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* [[B:%.*]], i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
35; CHECK-NEXT:    [[TMP3:%.*]] = load i8, i8* [[A_BASE]], align 1
36; CHECK-NEXT:    [[TMP4:%.*]] = load i8, i8* [[B_BASE]], align 1
37; CHECK-NEXT:    [[CMP_ELEM0:%.*]] = icmp eq i8 [[TMP3]], [[TMP4]]
38; CHECK-NEXT:    br i1 [[CMP_ELEM0]], label [[LAND_ELEM1:%.*]], label [[OPEQ_EXIT]]
39; CHECK:       opeq.exit:
40; CHECK-NEXT:    [[TMP5:%.*]] = phi i1 [ [[CMP_ELEM0]], [[LAND_ELEM0]] ], [ [[TMP2]], [[LAND_ELEM1]] ]
41; CHECK-NEXT:    ret i1 [[TMP5]]
42;
43  %"class.std::tuple"* nocapture readonly dereferenceable(4) %a,
44  %"class.std::tuple"* nocapture readonly dereferenceable(4) %b) local_unnamed_addr #1 {
45entry:
46  %a.base = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* %a, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
47  %a.elem3.addr = getelementptr inbounds i8, i8* %a.base, i64 3
48  %0 = load i8, i8* %a.elem3.addr, align 1
49  %b.base = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* %b, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
50  %b.elem3.addr = getelementptr inbounds i8, i8* %b.base, i64 3
51  %1 = load i8, i8* %b.elem3.addr, align 1
52  %cmp.elem3 = icmp eq i8 %0, %1
53  br i1 %cmp.elem3, label %land.elem2, label %opeq.exit
54
55land.elem2:
56  %a.elem2.addr = getelementptr inbounds i8, i8* %a.base, i64 2
57  %2 = load i8, i8* %a.elem2.addr, align 1
58  %b.elem2.addr = getelementptr inbounds i8, i8* %b.base, i64 2
59  %3 = load i8, i8* %b.elem2.addr, align 1
60  %cmp.elem2 = icmp eq i8 %2, %3
61  br i1 %cmp.elem2, label %land.elem1, label %opeq.exit
62
63land.elem1:
64  %a.elem1.addr = getelementptr inbounds i8, i8* %a.base, i64 1
65  %4 = load i8, i8* %a.elem1.addr, align 1
66  %b.elem1.addr = getelementptr inbounds i8, i8* %b.base, i64 1
67  %5 = load i8, i8* %b.elem1.addr, align 1
68  %cmp.elem1 = icmp eq i8 %4, %5
69  br i1 %cmp.elem1, label %land.elem0, label %opeq.exit
70
71land.elem0:
72  %6 = load i8, i8* %a.base, align 1
73  %7 = load i8, i8* %b.base, align 1
74  %cmp.elem0 = icmp eq i8 %6, %7
75  br label %opeq.exit
76
77opeq.exit:
78  %8 = phi i1 [ false, %entry ], [ false, %land.elem2 ], [ false, %land.elem1 ], [ %cmp.elem0, %land.elem0 ]
79  ret i1 %8
80}
81
82