llvm.org GIT mirror llvm / a593b70
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365439 91177308-0d34-0410-b5e6-96231b3b80d8 Yevgeny Rouban 1 year, 4 months ago
2 changed file(s) with 2 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
39123912 if (ProfileData->getNumOperands() != SI.getNumSuccessors() + 1) {
39133913 State = Invalid;
39143914 if (SwitchInstProfUpdateWrapperStrict)
3915 assert(false &&
3916 "number of prof branch_weights metadata operands corresponds to"
3917 " number of succesors");
3915 llvm_unreachable("number of prof branch_weights metadata operands does "
3916 "not correspond to number of succesors");
39183917 return;
39193918 }
39203919
786786 }
787787
788788 { // Create another wrapper and check that the data persist.
789 SwitchInstProfUpdateWrapper SIW(*SI);
790 EXPECT_EQ(*SIW.getSuccessorWeight(0), 99u);
791 EXPECT_EQ(*SIW.getSuccessorWeight(1), 11u);
792 EXPECT_EQ(*SIW.getSuccessorWeight(2), 22u);
793 }
794
795 // Make prof data invalid by adding one extra weight.
796 SI->setMetadata(LLVMContext::MD_prof, MDBuilder(C).createBranchWeights(
797 { 99, 11, 22, 33 })); // extra
798 { // Invalid prof data makes wrapper act as if there were no prof data.
799 SwitchInstProfUpdateWrapper SIW(*SI);
800 ASSERT_FALSE(SIW.getSuccessorWeight(0).hasValue());
801 ASSERT_FALSE(SIW.getSuccessorWeight(1).hasValue());
802 ASSERT_FALSE(SIW.getSuccessorWeight(2).hasValue());
803 SIW.addCase(ConstantInt::get(Int32Ty, 3), BB3.get(), 39);
804 ASSERT_FALSE(SIW.getSuccessorWeight(3).hasValue()); // did not add weight 39
805 }
806
807 { // With added 3rd case the prof data become consistent with num of cases.
808 SwitchInstProfUpdateWrapper SIW(*SI);
809 EXPECT_EQ(*SIW.getSuccessorWeight(0), 99u);
810 EXPECT_EQ(*SIW.getSuccessorWeight(1), 11u);
811 EXPECT_EQ(*SIW.getSuccessorWeight(2), 22u);
812 EXPECT_EQ(*SIW.getSuccessorWeight(3), 33u);
813 }
814
815 // Make prof data invalid by removing one extra weight.
816 SI->setMetadata(LLVMContext::MD_prof,
817 MDBuilder(C).createBranchWeights({ 99, 11, 22 })); // shorter
818 { // Invalid prof data makes wrapper act as if there were no prof data.
819 SwitchInstProfUpdateWrapper SIW(*SI);
820 ASSERT_FALSE(SIW.getSuccessorWeight(0).hasValue());
821 ASSERT_FALSE(SIW.getSuccessorWeight(1).hasValue());
822 ASSERT_FALSE(SIW.getSuccessorWeight(2).hasValue());
823 SIW.removeCase(SwitchInst::CaseIt(SI, 2));
824 }
825
826 { // With removed 3rd case the prof data become consistent with num of cases.
827789 SwitchInstProfUpdateWrapper SIW(*SI);
828790 EXPECT_EQ(*SIW.getSuccessorWeight(0), 99u);
829791 EXPECT_EQ(*SIW.getSuccessorWeight(1), 11u);