@@ -3432,7 +3432,7 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
3432
3432
static bool isSafeToRemoveBitCeilSelect (ICmpInst::Predicate Pred, Value *Cond0,
3433
3433
const APInt *Cond1, Value *CtlzOp,
3434
3434
unsigned BitWidth,
3435
- bool &ShouldDropNUW ) {
3435
+ bool &ShouldDropNoWrap ) {
3436
3436
// The challenge in recognizing std::bit_ceil(X) is that the operand is used
3437
3437
// for the CTLZ proper and select condition, each possibly with some
3438
3438
// operation like add and sub.
@@ -3455,7 +3455,7 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
3455
3455
ConstantRange CR = ConstantRange::makeExactICmpRegion (
3456
3456
CmpInst::getInversePredicate (Pred), *Cond1);
3457
3457
3458
- ShouldDropNUW = false ;
3458
+ ShouldDropNoWrap = false ;
3459
3459
3460
3460
// Match the operation that's used to compute CtlzOp from CommonAncestor. If
3461
3461
// CtlzOp == CommonAncestor, return true as no operation is needed. If a
@@ -3466,11 +3466,12 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
3466
3466
if (CtlzOp == CommonAncestor)
3467
3467
return true ;
3468
3468
if (match (CtlzOp, m_Add (m_Specific (CommonAncestor), m_APInt (C)))) {
3469
+ ShouldDropNoWrap = true ;
3469
3470
CR = CR.add (*C);
3470
3471
return true ;
3471
3472
}
3472
3473
if (match (CtlzOp, m_Sub (m_APInt (C), m_Specific (CommonAncestor)))) {
3473
- ShouldDropNUW = true ;
3474
+ ShouldDropNoWrap = true ;
3474
3475
CR = ConstantRange (*C).sub (CR);
3475
3476
return true ;
3476
3477
}
@@ -3541,19 +3542,21 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder,
3541
3542
Pred = CmpInst::getInversePredicate (Pred);
3542
3543
}
3543
3544
3544
- bool ShouldDropNUW ;
3545
+ bool ShouldDropNoWrap ;
3545
3546
3546
3547
if (!match (FalseVal, m_One ()) ||
3547
3548
!match (TrueVal,
3548
3549
m_OneUse (m_Shl (m_One (), m_OneUse (m_Sub (m_SpecificInt (BitWidth),
3549
3550
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 ())) ||
3551
3552
!isSafeToRemoveBitCeilSelect (Pred, Cond0, Cond1, CtlzOp, BitWidth,
3552
- ShouldDropNUW ))
3553
+ ShouldDropNoWrap ))
3553
3554
return nullptr ;
3554
3555
3555
- if (ShouldDropNUW)
3556
+ if (ShouldDropNoWrap) {
3556
3557
cast<Instruction>(CtlzOp)->setHasNoUnsignedWrap (false );
3558
+ cast<Instruction>(CtlzOp)->setHasNoSignedWrap (false );
3559
+ }
3557
3560
3558
3561
// Build 1 << (-CTLZ & (BitWidth-1)). The negation likely corresponds to a
3559
3562
// single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth
@@ -3562,6 +3565,8 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder,
3562
3565
3563
3566
// Drop range attributes and re-infer them in the next iteration.
3564
3567
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 ());
3565
3570
IC.addToWorklist (cast<Instruction>(Ctlz));
3566
3571
Value *Neg = Builder.CreateNeg (Ctlz);
3567
3572
Value *Masked =
0 commit comments