Skip to content

Commit b371854

Browse files
Simplified code.
Test class: - no longer using IRBuilder to create FRem instructions - no need to use ArmPL vector library
1 parent 89aa034 commit b371854

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,12 +1154,10 @@ bool TargetLibraryInfoImpl::getLibFunc(const Instruction &I, LibFunc &F) const {
11541154
return false;
11551155

11561156
Type *ScalarTy = I.getType()->getScalarType();
1157-
if (ScalarTy->isDoubleTy())
1158-
F = LibFunc_fmod;
1159-
else if (ScalarTy->isFloatTy())
1160-
F = LibFunc_fmodf;
1161-
else
1157+
if (!ScalarTy->isDoubleTy() && !ScalarTy->isFloatTy())
11621158
return false;
1159+
1160+
F = ScalarTy->isDoubleTy() ? LibFunc_fmod : LibFunc_fmodf;
11631161
return true;
11641162
}
11651163

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "llvm/Analysis/TargetLibraryInfo.h"
1010
#include "llvm/AsmParser/Parser.h"
11-
#include "llvm/IR/IRBuilder.h"
1211
#include "llvm/IR/LLVMContext.h"
1312
#include "llvm/IR/Module.h"
1413
#include "llvm/Support/SourceMgr.h"
@@ -625,59 +624,41 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
625624

626625
namespace {
627626

628-
// Creates TLI for AArch64 and VecLibrary ARmPL, and uses it to get the TLI
629-
// names for different FRem Instructions.
630-
class TLITestAarch64ArmPl : public ::testing::Test {
627+
/// Creates TLI for AArch64 and uses it to get the LibFunc names for the FRem
628+
/// Instruction.
629+
class TLITestAarch64 : public ::testing::Test {
631630
private:
632-
SMDiagnostic Err;
633631
const Triple TargetTriple;
634-
const TargetLibraryInfoImpl::VectorLibrary VecLib;
635632

636633
protected:
637634
LLVMContext Ctx;
638-
std::unique_ptr<Module> M;
639635
std::unique_ptr<TargetLibraryInfoImpl> TLII;
640636
std::unique_ptr<TargetLibraryInfo> TLI;
641637

642-
/// Create TLI for AArch64 with VecLib ArmPL.
643-
TLITestAarch64ArmPl()
644-
: TargetTriple(Triple("aarch64-unknown-linux-gnu")),
645-
VecLib(TargetLibraryInfoImpl::ArmPL) {
638+
/// Create TLI for AArch64
639+
TLITestAarch64() : TargetTriple(Triple("aarch64-unknown-linux-gnu")) {
646640
TLII = std::make_unique<TargetLibraryInfoImpl>(
647641
TargetLibraryInfoImpl(TargetTriple));
648-
TLII->addVectorizableFunctionsFromVecLib(VecLib, TargetTriple);
642+
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::NoLibrary,
643+
TargetTriple);
649644
TLI = std::make_unique<TargetLibraryInfo>(TargetLibraryInfo(*TLII));
650-
// Create a dummy module needed for tests.
651-
M = parseAssemblyString("declare void @dummy()", Err, Ctx);
652-
EXPECT_NE(M.get(), nullptr)
653-
<< "Loading an invalid module.\n " << Err.getMessage() << "\n";
654645
}
655646

656647
/// Creates an FRem Instruction of Type \p Ty, and uses it to get the TLI
657648
/// function name.
658649
StringRef getFremScalarName(Type *Ty) {
659-
// Use a dummy function and a BB to create an FRem Instruction.
660-
FunctionType *FTy = FunctionType::get(Ty, {Ty, Ty}, false);
661-
Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", *M);
662-
BasicBlock *BB = BasicBlock::Create(Ctx, "entry", F);
663-
IRBuilder<> Builder(BB);
664-
Builder.SetInsertPoint(BB);
665-
auto *FRem =
666-
dyn_cast<Instruction>(Builder.CreateFRem(F->getArg(0), F->getArg(1)));
667-
668-
// Use TLI to get LibFunc and then the TLI name.
650+
Value *V = Constant::getNullValue(Ty);
651+
Instruction *FRem = BinaryOperator::Create(Instruction::FRem, V, V);
669652
LibFunc Func;
670653
if (!TLI->getLibFunc(*FRem, Func))
671654
return "";
672-
auto FuncName = TLI->getName(Func);
673-
// Erase tmp function to prepare for the next test.
674-
F->eraseFromParent();
675-
return FuncName;
655+
FRem->deleteValue();
656+
return TLI->getName(Func);
676657
}
677658
};
678659
} // end anonymous namespace
679660

680-
TEST_F(TLITestAarch64ArmPl, TestFrem) {
661+
TEST_F(TLITestAarch64, TestFrem) {
681662
EXPECT_EQ(getFremScalarName(Type::getDoubleTy(Ctx)), "fmod");
682663
EXPECT_EQ(getFremScalarName(Type::getFloatTy(Ctx)), "fmodf");
683664
}

0 commit comments

Comments
 (0)