From f3d4166368b0449baea1e7d8e043d0fe76930179 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 29 Mar 2020 22:10:31 +0200 Subject: [PATCH] [InstCombine] Report change in non zero phi transform We need to inform InstCombine (and transitively the pass manager) that we changed an instruction. --- llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp index 6c2aead..9cdb68d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp @@ -1194,15 +1194,22 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) { if (CmpInst && isa(PN.getType()) && CmpInst->isEquality() && match(CmpInst->getOperand(1), m_Zero())) { ConstantInt *NonZeroConst = nullptr; + bool MadeChange = false; for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) { Instruction *CtxI = PN.getIncomingBlock(i)->getTerminator(); Value *VA = PN.getIncomingValue(i); if (isKnownNonZero(VA, DL, 0, &AC, CtxI, &DT)) { if (!NonZeroConst) NonZeroConst = GetAnyNonZeroConstInt(PN); - PN.setIncomingValue(i, NonZeroConst); + + if (NonZeroConst != VA) { + PN.setIncomingValue(i, NonZeroConst); + MadeChange = true; + } } } + if (MadeChange) + return &PN; } } -- 2.7.4