diff options
Diffstat (limited to 'llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp')
| -rw-r--r-- | llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp b/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp index c8fd366bfac6..9f76e9ff11c3 100644 --- a/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp +++ b/llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp @@ -469,3 +469,38 @@ TEST_F(FunctionSpecializationTest, PhiNode) { EXPECT_TRUE(Test > 0); } +TEST_F(FunctionSpecializationTest, BinOp) { + // Verify that we can handle binary operators even when only one operand is + // constant. + const char *ModuleString = R"( + define i32 @foo(i1 %a, i1 %b) { + %and1 = and i1 %a, %b + %and2 = and i1 %b, %and1 + %sel = select i1 %and2, i32 1, i32 0 + ret i32 %sel + } + )"; + + Module &M = parseModule(ModuleString); + Function *F = M.getFunction("foo"); + FunctionSpecializer Specializer = getSpecializerFor(F); + InstCostVisitor Visitor = Specializer.getInstCostVisitorFor(F); + + Constant *False = ConstantInt::getFalse(M.getContext()); + BasicBlock &BB = F->front(); + Instruction &And1 = BB.front(); + Instruction &And2 = *++BB.begin(); + Instruction &Select = *++BB.begin(); + + Cost RefCodeSize = getCodeSizeSavings(And1) + getCodeSizeSavings(And2) + + getCodeSizeSavings(Select); + Cost RefLatency = getLatencySavings(F); + + Cost TestCodeSize = Visitor.getCodeSizeSavingsForArg(F->getArg(0), False); + Cost TestLatency = Visitor.getLatencySavingsForKnownConstants(); + + EXPECT_EQ(TestCodeSize, RefCodeSize); + EXPECT_TRUE(TestCodeSize > 0); + EXPECT_EQ(TestLatency, RefLatency); + EXPECT_TRUE(TestLatency > 0); +} |
