[PATCH] D59593: [ExpandMemCmp] Trigger on bcmp too.

Clement Courbet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 03:11:11 PDT 2019


courbet created this revision.
courbet added a reviewer: gchatelet.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Fixes 41150.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59593

Files:
  llvm/lib/CodeGen/ExpandMemCmp.cpp
  llvm/test/CodeGen/X86/memcmp-optsize.ll


Index: llvm/test/CodeGen/X86/memcmp-optsize.ll
===================================================================
--- llvm/test/CodeGen/X86/memcmp-optsize.ll
+++ llvm/test/CodeGen/X86/memcmp-optsize.ll
@@ -10,6 +10,7 @@
 @.str = private constant [65 x i8] c"0123456789012345678901234567890123456789012345678901234567890123\00", align 1
 
 declare i32 @memcmp(i8*, i8*, i64)
+declare i32 @bcmp(i8*, i8*, i64)
 
 define i32 @length2(i8* %X, i8* %Y) nounwind optsize {
 ; X86-LABEL: length2:
@@ -982,3 +983,31 @@
   ret i1 %c
 }
 
+define i32 @bcmp_length2(i8* %X, i8* %Y) nounwind optsize {
+; X86-LABEL: bcmp_length2:
+; X86:       # %bb.0:
+; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
+; X86-NEXT:    movzwl (%ecx), %ecx
+; X86-NEXT:    movzwl (%eax), %edx
+; X86-NEXT:    rolw $8, %cx
+; X86-NEXT:    rolw $8, %dx
+; X86-NEXT:    movzwl %cx, %eax
+; X86-NEXT:    movzwl %dx, %ecx
+; X86-NEXT:    subl %ecx, %eax
+; X86-NEXT:    retl
+;
+; X64-LABEL: bcmp_length2:
+; X64:       # %bb.0:
+; X64-NEXT:    movzwl (%rdi), %eax
+; X64-NEXT:    movzwl (%rsi), %ecx
+; X64-NEXT:    rolw $8, %ax
+; X64-NEXT:    rolw $8, %cx
+; X64-NEXT:    movzwl %ax, %eax
+; X64-NEXT:    movzwl %cx, %ecx
+; X64-NEXT:    subl %ecx, %eax
+; X64-NEXT:    retq
+  %m = tail call i32 @bcmp(i8* %X, i8* %Y, i64 2) nounwind
+  ret i32 %m
+}
+
Index: llvm/lib/CodeGen/ExpandMemCmp.cpp
===================================================================
--- llvm/lib/CodeGen/ExpandMemCmp.cpp
+++ llvm/lib/CodeGen/ExpandMemCmp.cpp
@@ -823,7 +823,8 @@
     }
     LibFunc Func;
     if (TLI->getLibFunc(ImmutableCallSite(CI), Func) &&
-        Func == LibFunc_memcmp && expandMemCmp(CI, TTI, TL, &DL)) {
+        (Func == LibFunc_memcmp || Func == LibFunc_bcmp) &&
+        expandMemCmp(CI, TTI, TL, &DL)) {
       return true;
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59593.191464.patch
Type: text/x-patch
Size: 1853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190320/e9426b4c/attachment.bin>


More information about the llvm-commits mailing list