Index: lib/Transforms/InstCombine/InstCombineSelect.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineSelect.cpp +++ lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1820,14 +1820,8 @@ if (MDNode *MD = SI.getMetadata(LLVMContext::MD_prof)) { cast(NewMinMax)->setMetadata(LLVMContext::MD_prof, MD); // Swap the metadata if the operands are swapped. - if (Swapped) { - assert(X == SI.getFalseValue() && Y == SI.getTrueValue() && - "Unexpected operands."); + if (Swapped) cast(NewMinMax)->swapProfMetadata(); - } else { - assert(X == SI.getTrueValue() && Y == SI.getFalseValue() && - "Unexpected operands."); - } } return BinaryOperator::CreateNot(NewMinMax); Index: test/Transforms/InstCombine/select-pr39595.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/select-pr39595.ll @@ -0,0 +1,32 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +%0 = type { %1 } +%1 = type { %2* } +%2 = type { i32, i32* } + +$foo = comdat any + +; Function Attrs: inlinehint norecurse +define linkonce_odr dso_local i32 @foo(%0* dereferenceable(4)) local_unnamed_addr comdat !prof !1 { +; CHECK-LABEL: foo +; CHECK: [[TMP1:%.*]] = load i32*, i32** inttoptr (i64 8 to i32**), align 8 +; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[TMP1]], align 4 +; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* inttoptr (i64 4 to i32*), align 4 +; CHECK-NEXT: [[TMP4:%.*]] = icmp ugt i32 [[TMP2]], [[TMP3]] +; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP4]], i32 [[TMP2]], i32 [[TMP3]], !prof ![[$MD1:[0-9]+]] +; CHECK-DAG: ![[$MD1]] = !{!"branch_weights", i32 1, i32 6} + + %2 = getelementptr inbounds %2, %2* null, i32 0, i32 1 + %3 = load i32*, i32** %2, align 4 + %4 = load i32, i32* %3, align 4 + %5 = xor i32 %4, -1 + %6 = getelementptr inbounds i32, i32* null, i32 1 + %7 = load i32, i32* %6, align 4 + %8 = xor i32 %7, -1 + %9 = icmp ugt i32 %5, %8 + %10 = select i1 %9, i32 %8, i32 %5, !prof !2 + ret i32 %10 +} + +!1 = !{!"function_entry_count", i64 1} +!2 = !{!"branch_weights", i32 1, i32 6}