[llvm] r365439 - Prepare for making SwitchInstProfUpdateWrapper strict
Yevgeny Rouban via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 22:07:28 PDT 2019
Author: yrouban
Date: Mon Jul 8 22:07:28 2019
New Revision: 365439
URL: http://llvm.org/viewvc/llvm-project?rev=365439&view=rev
Log:
Prepare for making SwitchInstProfUpdateWrapper strict
This patch removes the test part that relates to the non-strict
behavior of SwitchInstProfUpdateWrapper and changes
the assertion to llvm_unreachable() to allow the check in
release builds.
This patch prepares SwitchInstProfUpdateWrapper to become
strict with one line change. That is need to revert it easily
if any failure will arise.
Modified:
llvm/trunk/lib/IR/Instructions.cpp
llvm/trunk/unittests/IR/InstructionsTest.cpp
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=365439&r1=365438&r2=365439&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Mon Jul 8 22:07:28 2019
@@ -3913,9 +3913,8 @@ void SwitchInstProfUpdateWrapper::init()
if (ProfileData->getNumOperands() != SI.getNumSuccessors() + 1) {
State = Invalid;
if (SwitchInstProfUpdateWrapperStrict)
- assert(false &&
- "number of prof branch_weights metadata operands corresponds to"
- " number of succesors");
+ llvm_unreachable("number of prof branch_weights metadata operands does "
+ "not correspond to number of succesors");
return;
}
Modified: llvm/trunk/unittests/IR/InstructionsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/InstructionsTest.cpp?rev=365439&r1=365438&r2=365439&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/InstructionsTest.cpp (original)
+++ llvm/trunk/unittests/IR/InstructionsTest.cpp Mon Jul 8 22:07:28 2019
@@ -792,44 +792,6 @@ TEST(InstructionsTest, SwitchInstProfUpd
EXPECT_EQ(*SIW.getSuccessorWeight(1), 11u);
EXPECT_EQ(*SIW.getSuccessorWeight(2), 22u);
}
-
- // Make prof data invalid by adding one extra weight.
- SI->setMetadata(LLVMContext::MD_prof, MDBuilder(C).createBranchWeights(
- { 99, 11, 22, 33 })); // extra
- { // Invalid prof data makes wrapper act as if there were no prof data.
- SwitchInstProfUpdateWrapper SIW(*SI);
- ASSERT_FALSE(SIW.getSuccessorWeight(0).hasValue());
- ASSERT_FALSE(SIW.getSuccessorWeight(1).hasValue());
- ASSERT_FALSE(SIW.getSuccessorWeight(2).hasValue());
- SIW.addCase(ConstantInt::get(Int32Ty, 3), BB3.get(), 39);
- ASSERT_FALSE(SIW.getSuccessorWeight(3).hasValue()); // did not add weight 39
- }
-
- { // With added 3rd case the prof data become consistent with num of cases.
- SwitchInstProfUpdateWrapper SIW(*SI);
- EXPECT_EQ(*SIW.getSuccessorWeight(0), 99u);
- EXPECT_EQ(*SIW.getSuccessorWeight(1), 11u);
- EXPECT_EQ(*SIW.getSuccessorWeight(2), 22u);
- EXPECT_EQ(*SIW.getSuccessorWeight(3), 33u);
- }
-
- // Make prof data invalid by removing one extra weight.
- SI->setMetadata(LLVMContext::MD_prof,
- MDBuilder(C).createBranchWeights({ 99, 11, 22 })); // shorter
- { // Invalid prof data makes wrapper act as if there were no prof data.
- SwitchInstProfUpdateWrapper SIW(*SI);
- ASSERT_FALSE(SIW.getSuccessorWeight(0).hasValue());
- ASSERT_FALSE(SIW.getSuccessorWeight(1).hasValue());
- ASSERT_FALSE(SIW.getSuccessorWeight(2).hasValue());
- SIW.removeCase(SwitchInst::CaseIt(SI, 2));
- }
-
- { // With removed 3rd case the prof data become consistent with num of cases.
- SwitchInstProfUpdateWrapper SIW(*SI);
- EXPECT_EQ(*SIW.getSuccessorWeight(0), 99u);
- EXPECT_EQ(*SIW.getSuccessorWeight(1), 11u);
- EXPECT_EQ(*SIW.getSuccessorWeight(2), 22u);
- }
}
TEST(InstructionsTest, CommuteShuffleMask) {
More information about the llvm-commits
mailing list