diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -319,9 +319,6 @@ assert(IncomingBlocks.size() == 2 && "Only for a pair of incoming blocks at the time!"); - // FIXME: it is okay if one of the incoming values is an `undef` value, - // iff the other incoming value is guaranteed to be a non-poison value. - // FIXME: it is okay if one of the incoming values is a `poison` value. return all_of(BB->phis(), [IncomingBlocks, EquivalenceSet](PHINode &PN) { Value *IV0 = PN.getIncomingValueForBlock(IncomingBlocks[0]); Value *IV1 = PN.getIncomingValueForBlock(IncomingBlocks[1]); @@ -330,6 +327,19 @@ if (EquivalenceSet && EquivalenceSet->contains(IV0) && EquivalenceSet->contains(IV1)) return true; + + // It is okay if one of the incoming values is an `undef` value, iff the + // other incoming value is guaranteed to be a non-poison value. + if (isa(IV0) && isGuaranteedNotToBePoison(IV1)) + return true; + if (isa(IV1) && isGuaranteedNotToBePoison(IV0)) + return true; + + // It is okay if one of the incoming values is a `poison` value. + if (isa(IV0) && !isa(IV1)) + return true; + if (isa(IV1) && !isa(IV0)) + return true; return false; }); }