[PATCH] D123849: [ExpandMemCmp] Properly expand `bcmp` to an equality pattern.
Clement Courbet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 15 02:17:41 PDT 2022
courbet updated this revision to Diff 423053.
courbet added a comment.
Rebase on base test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123849/new/
https://reviews.llvm.org/D123849
Files:
llvm/lib/CodeGen/ExpandMemCmp.cpp
llvm/test/Transforms/ExpandMemCmp/X86/bcmp.ll
Index: llvm/test/Transforms/ExpandMemCmp/X86/bcmp.ll
===================================================================
--- llvm/test/Transforms/ExpandMemCmp/X86/bcmp.ll
+++ llvm/test/Transforms/ExpandMemCmp/X86/bcmp.ll
@@ -9,14 +9,9 @@
; X64-NEXT: [[TMP2:%.*]] = bitcast i8* [[Y:%.*]] to i64*
; X64-NEXT: [[TMP3:%.*]] = load i64, i64* [[TMP1]], align 1
; X64-NEXT: [[TMP4:%.*]] = load i64, i64* [[TMP2]], align 1
-; X64-NEXT: [[TMP5:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP3]])
-; X64-NEXT: [[TMP6:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP4]])
-; X64-NEXT: [[TMP7:%.*]] = icmp ugt i64 [[TMP5]], [[TMP6]]
-; X64-NEXT: [[TMP8:%.*]] = icmp ult i64 [[TMP5]], [[TMP6]]
-; X64-NEXT: [[TMP9:%.*]] = zext i1 [[TMP7]] to i32
-; X64-NEXT: [[TMP10:%.*]] = zext i1 [[TMP8]] to i32
-; X64-NEXT: [[TMP11:%.*]] = sub i32 [[TMP9]], [[TMP10]]
-; X64-NEXT: ret i32 [[TMP11]]
+; X64-NEXT: [[TMP5:%.*]] = icmp ne i64 [[TMP3]], [[TMP4]]
+; X64-NEXT: [[TMP6:%.*]] = zext i1 [[TMP5]] to i32
+; X64-NEXT: ret i32 [[TMP6]]
;
%call = tail call i32 @bcmp(i8* %x, i8* %y, i64 8)
ret i32 %call
Index: llvm/lib/CodeGen/ExpandMemCmp.cpp
===================================================================
--- llvm/lib/CodeGen/ExpandMemCmp.cpp
+++ llvm/lib/CodeGen/ExpandMemCmp.cpp
@@ -740,7 +740,7 @@
static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
const TargetLowering *TLI, const DataLayout *DL,
ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI,
- DomTreeUpdater *DTU) {
+ DomTreeUpdater *DTU, const bool IsBCmp) {
NumMemCmpCalls++;
// Early exit from expansion if -Oz.
@@ -760,7 +760,8 @@
}
// TTI call to check if target would like to expand memcmp. Also, get the
// available load sizes.
- const bool IsUsedForZeroCmp = isOnlyUsedInZeroEqualityComparison(CI);
+ const bool IsUsedForZeroCmp =
+ IsBCmp || isOnlyUsedInZeroEqualityComparison(CI);
bool OptForSize = CI->getFunction()->hasOptSize() ||
llvm::shouldOptimizeForSize(CI->getParent(), PSI, BFI);
auto Options = TTI->enableMemCmpExpansion(OptForSize,
@@ -864,7 +865,7 @@
LibFunc Func;
if (TLI->getLibFunc(*CI, Func) &&
(Func == LibFunc_memcmp || Func == LibFunc_bcmp) &&
- expandMemCmp(CI, TTI, TL, &DL, PSI, BFI, DTU)) {
+ expandMemCmp(CI, TTI, TL, &DL, PSI, BFI, DTU, Func == LibFunc_bcmp)) {
return true;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123849.423053.patch
Type: text/x-patch
Size: 2522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220415/6f4d0bf9/attachment.bin>
More information about the llvm-commits
mailing list