Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/lib/Target/SBF/SBFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SBF/SBFTargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class SBFTTIImpl : public BasicTTIImplBase<SBFTTIImpl> {
TTI::MemCmpExpansionOptions Options;
Options.LoadSizes = {8, 4, 2, 1};
Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
Options.AllowOverlappingLoads = true;
return Options;
}

Expand Down
36 changes: 36 additions & 0 deletions llvm/test/CodeGen/SBF/expand_memcmp.ll
Original file line number Diff line number Diff line change
@@ -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
}
Loading