@@ -3432,7 +3432,7 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
34323432static bool isSafeToRemoveBitCeilSelect (ICmpInst::Predicate Pred, Value *Cond0,
34333433 const APInt *Cond1, Value *CtlzOp,
34343434 unsigned BitWidth,
3435- bool &ShouldDropNUW ) {
3435+ bool &ShouldDropNoWrap ) {
34363436 // The challenge in recognizing std::bit_ceil(X) is that the operand is used
34373437 // for the CTLZ proper and select condition, each possibly with some
34383438 // operation like add and sub.
@@ -3455,7 +3455,7 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
34553455 ConstantRange CR = ConstantRange::makeExactICmpRegion (
34563456 CmpInst::getInversePredicate (Pred), *Cond1);
34573457
3458- ShouldDropNUW = false ;
3458+ ShouldDropNoWrap = false ;
34593459
34603460 // Match the operation that's used to compute CtlzOp from CommonAncestor. If
34613461 // CtlzOp == CommonAncestor, return true as no operation is needed. If a
@@ -3466,11 +3466,12 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
34663466 if (CtlzOp == CommonAncestor)
34673467 return true ;
34683468 if (match (CtlzOp, m_Add (m_Specific (CommonAncestor), m_APInt (C)))) {
3469+ ShouldDropNoWrap = true ;
34693470 CR = CR.add (*C);
34703471 return true ;
34713472 }
34723473 if (match (CtlzOp, m_Sub (m_APInt (C), m_Specific (CommonAncestor)))) {
3473- ShouldDropNUW = true ;
3474+ ShouldDropNoWrap = true ;
34743475 CR = ConstantRange (*C).sub (CR);
34753476 return true ;
34763477 }
@@ -3541,19 +3542,21 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder,
35413542 Pred = CmpInst::getInversePredicate (Pred);
35423543 }
35433544
3544- bool ShouldDropNUW ;
3545+ bool ShouldDropNoWrap ;
35453546
35463547 if (!match (FalseVal, m_One ()) ||
35473548 !match (TrueVal,
35483549 m_OneUse (m_Shl (m_One (), m_OneUse (m_Sub (m_SpecificInt (BitWidth),
35493550 m_Value (Ctlz)))))) ||
3550- !match (Ctlz, m_Intrinsic<Intrinsic::ctlz>(m_Value (CtlzOp), m_Zero ())) ||
3551+ !match (Ctlz, m_Intrinsic<Intrinsic::ctlz>(m_Value (CtlzOp), m_Value ())) ||
35513552 !isSafeToRemoveBitCeilSelect (Pred, Cond0, Cond1, CtlzOp, BitWidth,
3552- ShouldDropNUW ))
3553+ ShouldDropNoWrap ))
35533554 return nullptr ;
35543555
3555- if (ShouldDropNUW)
3556+ if (ShouldDropNoWrap) {
35563557 cast<Instruction>(CtlzOp)->setHasNoUnsignedWrap (false );
3558+ cast<Instruction>(CtlzOp)->setHasNoSignedWrap (false );
3559+ }
35573560
35583561 // Build 1 << (-CTLZ & (BitWidth-1)). The negation likely corresponds to a
35593562 // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth
@@ -3562,6 +3565,8 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder,
35623565
35633566 // Drop range attributes and re-infer them in the next iteration.
35643567 cast<Instruction>(Ctlz)->dropPoisonGeneratingAnnotations ();
3568+ // Set is_zero_poison to false and re-infer them in the next iteration.
3569+ cast<Instruction>(Ctlz)->setOperand (1 , Builder.getFalse ());
35653570 IC.addToWorklist (cast<Instruction>(Ctlz));
35663571 Value *Neg = Builder.CreateNeg (Ctlz);
35673572 Value *Masked =
0 commit comments