Index: lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCompares.cpp +++ lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3777,6 +3777,11 @@ const unsigned SIOpd) { assert((SIOpd == 1 || SIOpd == 2) && "Invalid select operand!"); if (isChainSelectCmpBranch(SI) && Icmp->getPredicate() == ICmpInst::ICMP_EQ) { + // need to disable for the case branching to same block like + // br il %5, label %n, label %n. + if (SI->getParent()->getTerminator()->getSuccessor(1) == + SI->getParent()->getTerminator()->getSuccessor(0)) + return false; BasicBlock *Succ = SI->getParent()->getTerminator()->getSuccessor(1); // The check for the unique predecessor is not the best that can be // done. But it protects efficiently against cases like when SI's Index: test/Transforms/InstCombine/select-cmp-br.ll =================================================================== --- test/Transforms/InstCombine/select-cmp-br.ll +++ test/Transforms/InstCombine/select-cmp-br.ll @@ -153,3 +153,29 @@ ; CHECK: or ; CHECK-NOT: select } + +define void @test6(%C*) { +entry: + %1 = getelementptr inbounds %C, %C* %0, i64 0, i32 0, i32 0 + %m = load i64*, i64** %1, align 8 + %2 = getelementptr inbounds %C, %C* %0, i64 1, i32 0, i32 0 + %n = load i64*, i64** %2, align 8 + %3 = getelementptr inbounds i64, i64* %m, i64 9 + %4 = bitcast i64* %3 to i64 (%C*)** + %5 = load i64 (%C*)*, i64 (%C*)** %4, align 8 + %6 = icmp eq i64* %m, %n + %7 = select i1 %6, %C* %0, %C* null + %8 = icmp eq %C* %7, null + br i1 %8, label %10, label %10 + +;