Index: llvm/lib/IR/Instructions.cpp =================================================================== --- llvm/lib/IR/Instructions.cpp +++ llvm/lib/IR/Instructions.cpp @@ -49,7 +49,7 @@ "switch-inst-prof-update-wrapper-strict", cl::Hidden, cl::desc("Assert that prof branch_weights metadata is valid when creating " "an instance of SwitchInstProfUpdateWrapper"), - cl::init(false)); + cl::init(true)); //===----------------------------------------------------------------------===// // AllocaInst Class Index: llvm/unittests/IR/InstructionsTest.cpp =================================================================== --- llvm/unittests/IR/InstructionsTest.cpp +++ llvm/unittests/IR/InstructionsTest.cpp @@ -792,44 +792,6 @@ 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) {