Page MenuHomePhabricator

D59593.diff
No OneTemporary

File Metadata

Created
Tue, Aug 20, 2:14 PM

D59593.diff

Index: llvm/trunk/lib/CodeGen/ExpandMemCmp.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/ExpandMemCmp.cpp
+++ llvm/trunk/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;
}
}
Index: llvm/trunk/test/CodeGen/X86/memcmp-optsize.ll
===================================================================
--- llvm/trunk/test/CodeGen/X86/memcmp-optsize.ll
+++ llvm/trunk/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
+}
+

Event Timeline