diff options
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index b9957a9..b1f2e8b 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3779,23 +3779,20 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) { return replaceInstUsesWith(I, NI); if (match(Op0, m_Undef())) { - // If I is freeze(undef), see its uses and fold it to the best constant. + // If I is freeze(undef), check its uses and fold it to a fixed constant. // - or: pick -1 - // - select's condition: pick the value that leads to choosing a constant - // - other ops: pick 0 + // - select's condition: if the true value is constant, choose it by making + // the condition true. + // - default: pick 0 Constant *BestValue = nullptr; Constant *NullValue = Constant::getNullValue(I.getType()); for (const auto *U : I.users()) { Constant *C = NullValue; if (match(U, m_Or(m_Value(), m_Value()))) - C = Constant::getAllOnesValue(I.getType()); - else if (const auto *SI = dyn_cast<SelectInst>(U)) { - if (SI->getCondition() == &I) { - APInt CondVal(1, isa<Constant>(SI->getFalseValue()) ? 0 : 1); - C = Constant::getIntegerValue(I.getType(), CondVal); - } - } + C = ConstantInt::getAllOnesValue(I.getType()); + else if (match(U, m_Select(m_Specific(&I), m_Constant(), m_Value()))) + C = ConstantInt::getTrue(I.getType()); if (!BestValue) BestValue = C; |