summaryrefslogtreecommitdiff
path: root/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
diff options
context:
space:
mode:
authorZaara Syeda <syzaara@ca.ibm.com>2017-05-31 17:12:38 +0000
committerZaara Syeda <syzaara@ca.ibm.com>2017-05-31 17:12:38 +0000
commit682f92f5687cb1a0b9b5618ffca0078755eaaab6 (patch)
treebb1316924ab117fb22ce9d5da7f71431d704f0ba /test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
parent5e17e439ace0844d60a5c93e89b8b68c0a962419 (diff)
[PPC] Inline expansion of memcmp
This patch does an inline expansion of memcmp. It changes the memcmp library call into an inline expansion when the size is known at compile time and is under a target specified threshold. This expansion is implemented in CodeGenPrepare and expands into straight line code. The target specifies a maximum load size and the expansion works by using this size to load the two sources, compare, and exit early if a difference is found. It also has a special case when the memcmp result is used in a compare to zero equality. Differential Revision: https://reviews.llvm.org/D28637 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304313 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll')
-rw-r--r--test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll121
1 files changed, 121 insertions, 0 deletions
diff --git a/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll b/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
new file mode 100644
index 00000000000..3095429758f
--- /dev/null
+++ b/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
@@ -0,0 +1,121 @@
+; RUN: llc -verify-machineinstrs -mcpu=pwr8 < %s | FileCheck %s
+target datalayout = "e-m:e-i64:64-n32:64"
+target triple = "powerpc64le-unknown-linux-gnu"
+
+@zeroEqualityTest01.buffer1 = private unnamed_addr constant [3 x i32] [i32 1, i32 2, i32 4], align 4
+@zeroEqualityTest01.buffer2 = private unnamed_addr constant [3 x i32] [i32 1, i32 2, i32 3], align 4
+@zeroEqualityTest02.buffer1 = private unnamed_addr constant [4 x i32] [i32 4, i32 0, i32 0, i32 0], align 4
+@zeroEqualityTest02.buffer2 = private unnamed_addr constant [4 x i32] [i32 3, i32 0, i32 0, i32 0], align 4
+@zeroEqualityTest03.buffer1 = private unnamed_addr constant [4 x i32] [i32 0, i32 0, i32 0, i32 3], align 4
+@zeroEqualityTest03.buffer2 = private unnamed_addr constant [4 x i32] [i32 0, i32 0, i32 0, i32 4], align 4
+@zeroEqualityTest04.buffer1 = private unnamed_addr constant [15 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14], align 4
+@zeroEqualityTest04.buffer2 = private unnamed_addr constant [15 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 13], align 4
+
+; Function Attrs: nounwind readonly
+declare signext i32 @memcmp(i8* nocapture, i8* nocapture, i64) local_unnamed_addr #1
+
+; Validate with if(memcmp())
+; Function Attrs: nounwind readonly
+define signext i32 @zeroEqualityTest01() local_unnamed_addr #0 {
+entry:
+ %call = tail call signext i32 @memcmp(i8* bitcast ([3 x i32]* @zeroEqualityTest01.buffer1 to i8*), i8* bitcast ([3 x i32]* @zeroEqualityTest01.buffer2 to i8*), i64 16)
+ %not.tobool = icmp ne i32 %call, 0
+ %. = zext i1 %not.tobool to i32
+ ret i32 %.
+
+ ; CHECK-LABEL: @zeroEqualityTest01
+ ; CHECK-LABEL: %res_block
+ ; CHECK: li 3, 1
+ ; CHECK-NEXT: clrldi
+ ; CHECK-NEXT: blr
+ ; CHECK: li 3, 0
+ ; CHECK-NEXT: clrldi
+ ; CHECK-NEXT: blr
+}
+
+; Validate with if(memcmp() == 0)
+; Function Attrs: nounwind readonly
+define signext i32 @zeroEqualityTest02() local_unnamed_addr #0 {
+entry:
+ %call = tail call signext i32 @memcmp(i8* bitcast ([4 x i32]* @zeroEqualityTest02.buffer1 to i8*), i8* bitcast ([4 x i32]* @zeroEqualityTest02.buffer2 to i8*), i64 16)
+ %not.cmp = icmp ne i32 %call, 0
+ %. = zext i1 %not.cmp to i32
+ ret i32 %.
+
+ ; CHECK-LABEL: @zeroEqualityTest02
+ ; CHECK-LABEL: %res_block
+ ; CHECK: li 3, 1
+ ; CHECK-NEXT: clrldi
+ ; CHECK-NEXT: blr
+ ; CHECK: li 3, 0
+ ; CHECK-NEXT: clrldi
+ ; CHECK-NEXT: blr
+}
+
+; Validate with > 0
+; Function Attrs: nounwind readonly
+define signext i32 @zeroEqualityTest03() local_unnamed_addr #0 {
+entry:
+ %call = tail call signext i32 @memcmp(i8* bitcast ([4 x i32]* @zeroEqualityTest02.buffer1 to i8*), i8* bitcast ([4 x i32]* @zeroEqualityTest02.buffer2 to i8*), i64 16)
+ %not.cmp = icmp slt i32 %call, 1
+ %. = zext i1 %not.cmp to i32
+ ret i32 %.
+
+ ; CHECK-LABEL: @zeroEqualityTest03
+ ; CHECK-LABEL: %res_block
+ ; CHECK: cmpld
+ ; CHECK-NEXT: li [[LI:[0-9]+]], 1
+ ; CHECK-NEXT: li [[LI2:[0-9]+]], -1
+ ; CHECK-NEXT: isel [[ISEL:[0-9]+]], [[LI2]], [[LI]], 0
+}
+
+; Validate with < 0
+; Function Attrs: nounwind readonly
+define signext i32 @zeroEqualityTest04() local_unnamed_addr #0 {
+entry:
+ %call = tail call signext i32 @memcmp(i8* bitcast ([4 x i32]* @zeroEqualityTest03.buffer1 to i8*), i8* bitcast ([4 x i32]* @zeroEqualityTest03.buffer2 to i8*), i64 16)
+ %call.lobit = lshr i32 %call, 31
+ %call.lobit.not = xor i32 %call.lobit, 1
+ ret i32 %call.lobit.not
+
+ ; CHECK-LABEL: @zeroEqualityTest04
+ ; CHECK-LABEL: %res_block
+ ; CHECK: cmpld
+ ; CHECK-NEXT: li [[LI:[0-9]+]], 1
+ ; CHECK-NEXT: li [[LI2:[0-9]+]], -1
+ ; CHECK-NEXT: isel [[ISEL:[0-9]+]], [[LI2]], [[LI]], 0
+}
+
+; Validate with memcmp()?:
+; Function Attrs: nounwind readonly
+define signext i32 @zeroEqualityTest05() local_unnamed_addr #0 {
+entry:
+ %call = tail call signext i32 @memcmp(i8* bitcast ([15 x i32]* @zeroEqualityTest04.buffer1 to i8*), i8* bitcast ([15 x i32]* @zeroEqualityTest04.buffer2 to i8*), i64 16)
+ %not.tobool = icmp eq i32 %call, 0
+ %cond = zext i1 %not.tobool to i32
+ ret i32 %cond
+
+ ; CHECK-LABEL: @zeroEqualityTest05
+ ; CHECK-LABEL: %res_block
+ ; CHECK: li 3, 1
+ ; CHECK: li 3, 0
+}
+
+; Validate with !memcmp()?:
+; Function Attrs: nounwind readonly
+define signext i32 @zeroEqualityTest06() local_unnamed_addr #0 {
+entry:
+ %call = tail call signext i32 @memcmp(i8* bitcast ([15 x i32]* @zeroEqualityTest04.buffer1 to i8*), i8* bitcast ([15 x i32]* @zeroEqualityTest04.buffer2 to i8*), i64 16)
+ %not.lnot = icmp ne i32 %call, 0
+ %cond = zext i1 %not.lnot to i32
+ ret i32 %cond
+
+ ; CHECK-LABEL: @zeroEqualityTest06
+ ; CHECK-LABEL: %res_block
+ ; CHECK: li 3, 1
+ ; CHECK-NEXT: clrldi
+ ; CHECK-NEXT: blr
+ ; CHECK: li 3, 0
+ ; CHECK-NEXT: clrldi
+ ; CHECK-NEXT: blr
+}