diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 1398697dc55..d36d9dc1b96 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2096,7 +2096,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) { for (Instruction::op_iterator OI = BonusInst->op_begin(), OE = BonusInst->op_end(); OI != OE; ++OI) { Value *V = *OI; - if (!isa(V)) + if (!isa(V) && !isa(V)) UsedValues.insert(V); } diff --git a/test/Transforms/SimplifyCFG/common-dest-folding.ll b/test/Transforms/SimplifyCFG/common-dest-folding.ll new file mode 100644 index 00000000000..10fb7d497de --- /dev/null +++ b/test/Transforms/SimplifyCFG/common-dest-folding.ll @@ -0,0 +1,28 @@ +; RUN: opt < %s -simplifycfg -S | FileCheck %s + +;CHECK: @foo +;CHECK: and i32 %c1, %k +;CHECK: icmp eq i32 +;CHECK: and i32 %c2, %k +;CHECK: icmp eq i32 +;CHECK: or i1 +;CHECK: ret +define i32 @foo(i32 %k, i32 %c1, i32 %c2) { + %1 = and i32 %c1, %k + %2 = icmp eq i32 %1, 0 + br i1 %2, label %8, label %3 + +;