diff options
Diffstat (limited to 'llvm/test/Transforms')
-rw-r--r-- | llvm/test/Transforms/MergeICmps/pair-int32-int32.ll | 87 | ||||
-rw-r--r-- | llvm/test/Transforms/MergeICmps/tuple-four-int8.ll | 73 | ||||
-rw-r--r-- | llvm/test/Transforms/MergeICmps/volatile.ll | 30 |
3 files changed, 190 insertions, 0 deletions
diff --git a/llvm/test/Transforms/MergeICmps/pair-int32-int32.ll b/llvm/test/Transforms/MergeICmps/pair-int32-int32.ll new file mode 100644 index 00000000000..351cb2adedf --- /dev/null +++ b/llvm/test/Transforms/MergeICmps/pair-int32-int32.ll @@ -0,0 +1,87 @@ +; RUN: opt -mergeicmps -S -o - %s | FileCheck %s + +%"struct.std::pair" = type { i32, i32 } + +define zeroext i1 @opeq1( + %"struct.std::pair"* nocapture readonly dereferenceable(8) %a, + %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 { +entry: + %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 0 + %0 = load i32, i32* %first.i, align 4 + %first1.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 0 + %1 = load i32, i32* %first1.i, align 4 + %cmp.i = icmp eq i32 %0, %1 + br i1 %cmp.i, label %land.rhs.i, label %opeq1.exit + +land.rhs.i: + %second.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 1 + %2 = load i32, i32* %second.i, align 4 + %second2.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 1 + %3 = load i32, i32* %second2.i, align 4 + %cmp3.i = icmp eq i32 %2, %3 + br label %opeq1.exit + +opeq1.exit: + %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ] + ret i1 %4 +; CHECK-LABEL: @opeq1( +; The entry block with zero-offset GEPs is kept, loads are removed. +; CHECK: entry +; CHECK: getelementptr {{.*}} i32 0 +; CHECK-NOT: load +; CHECK: getelementptr {{.*}} i32 0 +; CHECK-NOT: load +; The two 4 byte loads and compares are replaced with a single 8-byte memcmp. +; CHECK: @memcmp({{.*}}8) +; CHECK: icmp eq {{.*}} 0 +; The branch is now a direct branch; the other block has been removed. +; CHECK: br label %opeq1.exit +; CHECK-NOT: br +; The phi is updated. +; CHECK: phi i1 [ %{{[^,]*}}, %entry ] +; CHECK-NEXT: ret +} + +; Same as above, but the two blocks are in inverse order. +define zeroext i1 @opeq1_inverse( + %"struct.std::pair"* nocapture readonly dereferenceable(8) %a, + %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 { +entry: + %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 1 + %0 = load i32, i32* %first.i, align 4 + %first1.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 1 + %1 = load i32, i32* %first1.i, align 4 + %cmp.i = icmp eq i32 %0, %1 + br i1 %cmp.i, label %land.rhs.i, label %opeq1.exit + +land.rhs.i: + %second.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 0 + %2 = load i32, i32* %second.i, align 4 + %second2.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 0 + %3 = load i32, i32* %second2.i, align 4 + %cmp3.i = icmp eq i32 %2, %3 + br label %opeq1.exit + +opeq1.exit: + %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ] + ret i1 %4 +; CHECK-LABEL: @opeq1_inverse( +; The second block with zero-offset GEPs is kept, loads are removed. +; CHECK: land.rhs.i +; CHECK: getelementptr {{.*}} i32 0 +; CHECK-NOT: load +; CHECK: getelementptr {{.*}} i32 0 +; CHECK-NOT: load +; The two 4 byte loads and compares are replaced with a single 8-byte memcmp. +; CHECK: @memcmp({{.*}}8) +; CHECK: icmp eq {{.*}} 0 +; The branch is now a direct branch; the other block has been removed. +; CHECK: br label %opeq1.exit +; CHECK-NOT: br +; The phi is updated. +; CHECK: phi i1 [ %{{[^,]*}}, %land.rhs.i ] +; CHECK-NEXT: ret +} + + + diff --git a/llvm/test/Transforms/MergeICmps/tuple-four-int8.ll b/llvm/test/Transforms/MergeICmps/tuple-four-int8.ll new file mode 100644 index 00000000000..f5e2ab57e04 --- /dev/null +++ b/llvm/test/Transforms/MergeICmps/tuple-four-int8.ll @@ -0,0 +1,73 @@ +; RUN: opt -mergeicmps -S -o - %s | FileCheck %s + +; This is a more involved test: clang generates this weird pattern for +; tuple<uint8_t, uint8_t, uint8_t, uint8_t>. Right now we skip the entry block +; (which defines the base pointer for other blocks) and the last one (which +; does not have the expected structure). Only middle blocks (bytes [1,2]) are +; merged. + +%"class.std::tuple" = type { %"struct.std::_Tuple_impl" } +%"struct.std::_Tuple_impl" = type { %"struct.std::_Tuple_impl.0", %"struct.std::_Head_base.6" } +%"struct.std::_Tuple_impl.0" = type { %"struct.std::_Tuple_impl.1", %"struct.std::_Head_base.5" } +%"struct.std::_Tuple_impl.1" = type { %"struct.std::_Tuple_impl.2", %"struct.std::_Head_base.4" } +%"struct.std::_Tuple_impl.2" = type { %"struct.std::_Head_base" } +%"struct.std::_Head_base" = type { i8 } +%"struct.std::_Head_base.4" = type { i8 } +%"struct.std::_Head_base.5" = type { i8 } +%"struct.std::_Head_base.6" = type { i8 } + +define zeroext i1 @opeq( + %"class.std::tuple"* nocapture readonly dereferenceable(4) %a, + %"class.std::tuple"* nocapture readonly dereferenceable(4) %b) local_unnamed_addr #1 { +entry: + %0 = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* %a, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 + %add.ptr.i.i.i.i.i = getelementptr inbounds i8, i8* %0, i64 3 + %1 = load i8, i8* %add.ptr.i.i.i.i.i, align 1 + %2 = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* %b, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 + %add.ptr.i.i.i6.i.i = getelementptr inbounds i8, i8* %2, i64 3 + %3 = load i8, i8* %add.ptr.i.i.i6.i.i, align 1 + %cmp.i.i = icmp eq i8 %1, %3 + br i1 %cmp.i.i, label %land.rhs.i.i, label %opeq.exit + +land.rhs.i.i: + %add.ptr.i.i.i.i.i.i = getelementptr inbounds i8, i8* %0, i64 2 + %4 = load i8, i8* %add.ptr.i.i.i.i.i.i, align 1 + %add.ptr.i.i.i6.i.i.i = getelementptr inbounds i8, i8* %2, i64 2 + %5 = load i8, i8* %add.ptr.i.i.i6.i.i.i, align 1 + %cmp.i.i.i = icmp eq i8 %4, %5 + br i1 %cmp.i.i.i, label %land.rhs.i.i.i, label %opeq.exit + +land.rhs.i.i.i: + %add.ptr.i.i.i.i.i.i.i = getelementptr inbounds i8, i8* %0, i64 1 + %6 = load i8, i8* %add.ptr.i.i.i.i.i.i.i, align 1 + %add.ptr.i.i.i6.i.i.i.i = getelementptr inbounds i8, i8* %2, i64 1 + %7 = load i8, i8* %add.ptr.i.i.i6.i.i.i.i, align 1 + %cmp.i.i.i.i = icmp eq i8 %6, %7 + br i1 %cmp.i.i.i.i, label %land.rhs.i.i.i.i, label %opeq.exit + +land.rhs.i.i.i.i: + %8 = load i8, i8* %0, align 1 + %9 = load i8, i8* %2, align 1 + %cmp.i.i.i.i.i = icmp eq i8 %8, %9 + br label %opeq.exit + +opeq.exit: + %10 = phi i1 [ false, %entry ], [ false, %land.rhs.i.i ], [ false, %land.rhs.i.i.i ], [ %cmp.i.i.i.i.i, %land.rhs.i.i.i.i ] + ret i1 %10 +; CHECK-LABEL: @opeq( +; The entry block is kept as is, but the next block is now the merged comparison +; block for bytes [1,2] or the block for the head. +; CHECK: entry +; CHECK: br i1 %cmp.i.i, label %land.rhs.i.i.i{{(.i)?}}, label %opeq.exit +; The two 1 byte loads and compares at offset 1 are replaced with a single +; 2-byte memcmp. +; CHECK: land.rhs.i.i.i +; CHECK: @memcmp({{.*}}2) +; CHECK: icmp eq {{.*}} 0 +; In the end we have three blocks. +; CHECK: phi i1 +; CHECK-SAME %entry +; CHECK-SAME %land.rhs.i.i.i.i +; CHECK-SAME %land.rhs.i.i.i +} + diff --git a/llvm/test/Transforms/MergeICmps/volatile.ll b/llvm/test/Transforms/MergeICmps/volatile.ll new file mode 100644 index 00000000000..1df22575c2c --- /dev/null +++ b/llvm/test/Transforms/MergeICmps/volatile.ll @@ -0,0 +1,30 @@ +; RUN: opt -mergeicmps -S -o - %s | FileCheck %s + +%"struct.std::pair" = type { i32, i32 } + +define zeroext i1 @opeq( + %"struct.std::pair"* nocapture readonly dereferenceable(8) %a, + %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 { +entry: + %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 0 + %0 = load i32, i32* %first.i, align 4 + %first1.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 0 + %1 = load i32, i32* %first1.i, align 4 + %cmp.i = icmp eq i32 %0, %1 + br i1 %cmp.i, label %land.rhs.i, label %opeq1.exit + +land.rhs.i: + %second.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 1 + %2 = load volatile i32, i32* %second.i, align 4 + %second2.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 1 + %3 = load i32, i32* %second2.i, align 4 + %cmp3.i = icmp eq i32 %2, %3 + br label %opeq1.exit + +opeq1.exit: + %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ] + ret i1 %4 +; CHECK-LABEL: @opeq( +; CHECK-NOT: memcmp +} + |