@@ -5014,7 +5014,8 @@ Instruction *InstCombinerImpl::visitLandingPadInst(LandingPadInst &LI) {
50145014}
50155015
50165016Value *
5017- InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating (FreezeInst &OrigFI) {
5017+ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating (FreezeInst &OrigFI,
5018+ bool PushThruPhis) {
50185019 // Try to push freeze through instructions that propagate but don't produce
50195020 // poison as far as possible. If an operand of freeze does not produce poison
50205021 // then push the freeze through to the operands that are not guaranteed
@@ -5027,8 +5028,8 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
50275028 // Op1.fr = Freeze(Op1)
50285029 // ... = Inst(Op1.fr, NonPoisonOps...)
50295030
5030- auto CanPushFreeze = [this ](Value *V) {
5031- if (!isa<Instruction>(V))
5031+ auto CanPushFreeze = [& ](Value *V) {
5032+ if (!isa<Instruction>(V) || (isa<PHINode>(V) && !PushThruPhis) )
50325033 return false ;
50335034
50345035 if (auto *PN = dyn_cast<PHINode>(V)) {
@@ -5231,15 +5232,19 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
52315232 if (Value *V = simplifyFreezeInst (Op0, SQ.getWithInstruction (&I)))
52325233 return replaceInstUsesWith (I, V);
52335234
5235+ bool PushThruPhis = false ;
52345236 // freeze (phi const, x) --> phi const, (freeze x)
52355237 if (auto *PN = dyn_cast<PHINode>(Op0)) {
52365238 if (Instruction *NV = foldOpIntoPhi (I, PN))
52375239 return NV;
5238- if (Instruction *NV = foldFreezeIntoRecurrence (I, PN))
5239- return NV;
5240+ if (FreezePhisVisited.insert (PN).second ) {
5241+ PushThruPhis = true ;
5242+ if (Instruction *NV = foldFreezeIntoRecurrence (I, PN))
5243+ return NV;
5244+ }
52405245 }
52415246
5242- if (Value *NI = pushFreezeToPreventPoisonFromPropagating (I))
5247+ if (Value *NI = pushFreezeToPreventPoisonFromPropagating (I, PushThruPhis ))
52435248 return replaceInstUsesWith (I, NI);
52445249
52455250 // If I is freeze(undef), check its uses and fold it to a fixed constant.
0 commit comments