diff --git a/llvm/lib/Target/SBF/SBFTargetMachine.cpp b/llvm/lib/Target/SBF/SBFTargetMachine.cpp index 36128b388cc30..c378af6e9febc 100644 --- a/llvm/lib/Target/SBF/SBFTargetMachine.cpp +++ b/llvm/lib/Target/SBF/SBFTargetMachine.cpp @@ -10,13 +10,14 @@ // //===----------------------------------------------------------------------===// +#include "MCTargetDesc/SBFMCAsmInfo.h" #include "SBF.h" +#include "SBFFunctionInfo.h" #include "SBFTargetMachine.h" #include "SBFTargetTransformInfo.h" -#include "SBFFunctionInfo.h" -#include "MCTargetDesc/SBFMCAsmInfo.h" #include "TargetInfo/SBFTargetInfo.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/CodeGen/ExpandMemCmp.h" #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/IR/PassManager.h" @@ -113,6 +114,7 @@ void SBFTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) { FPM.addPass(SBFAbstractMemberAccessPass(this)); FPM.addPass(SBFPreserveDITypePass()); FPM.addPass(SBFIRPeepholePass()); + FPM.addPass(ExpandMemCmpPass(this)); MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); }); PB.registerPeepholeEPCallback([=](FunctionPassManager &FPM, diff --git a/llvm/lib/Target/SBF/SBFTargetTransformInfo.h b/llvm/lib/Target/SBF/SBFTargetTransformInfo.h index fd684ff36cf96..82e7be7c8d1f4 100644 --- a/llvm/lib/Target/SBF/SBFTargetTransformInfo.h +++ b/llvm/lib/Target/SBF/SBFTargetTransformInfo.h @@ -87,6 +87,7 @@ class SBFTTIImpl : public BasicTTIImplBase { TTI::MemCmpExpansionOptions Options; Options.LoadSizes = {8, 4, 2, 1}; Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize); + Options.AllowOverlappingLoads = true; return Options; } diff --git a/llvm/test/CodeGen/SBF/expand_memcmp.ll b/llvm/test/CodeGen/SBF/expand_memcmp.ll new file mode 100644 index 0000000000000..d78c4d6344e45 --- /dev/null +++ b/llvm/test/CodeGen/SBF/expand_memcmp.ll @@ -0,0 +1,36 @@ +; RUN: opt -O2 -S < %s | FileCheck %s + +target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128" +target triple = "sbf" + +; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read) +declare i32 @memcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr + +; The memcmp is expanded with an overlaping load +define i1 @yes_expand(ptr %a, ptr %b) { +entry: + %res = call i32 @memcmp(ptr %a, ptr %b, i64 15) + %is_zero = icmp eq i32 %res, 0 + ret i1 %is_zero + +; CHECK: entry: +; CHECK: %0 = load i64, ptr %a, align 1 +; CHECK: %1 = load i64, ptr %b, align 1 +; CHECK: %.not = icmp eq i64 %0, %1 +; CHECK: br i1 %.not, label %loadbb1, label %res_block + +; CHECK: res_block: +; CHECK: br label %endblock + +; CHECK: loadbb1: +; CHECK: %2 = getelementptr i8, ptr %a, i64 7 +; CHECK: %3 = getelementptr i8, ptr %b, i64 7 +; CHECK: %4 = load i64, ptr %2, align 1 +; CHECK: %5 = load i64, ptr %3, align 1 +; CHECK: %.not2 = icmp eq i64 %4, %5 +; CHECK: br i1 %.not2, label %endblock, label %res_block + +; CHECK: endblock: +; CHECK: %is_zero = phi i1 [ true, %loadbb1 ], [ false, %res_block ] +; CHECK: ret i1 %is_zero +} \ No newline at end of file