@@ -3469,7 +3469,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
34693469// Note that the select is optimized away while the shift count is masked with
34703470// 31. We handle some variations of the input operand like std::bit_ceil(X +
34713471// 1).
3472- static Instruction *foldBitCeil (SelectInst &SI, IRBuilderBase &Builder) {
3472+ static Instruction *foldBitCeil (SelectInst &SI, IRBuilderBase &Builder,
3473+ InstCombinerImpl &IC) {
34733474 Type *SelType = SI.getType ();
34743475 unsigned BitWidth = SelType->getScalarSizeInBits ();
34753476
@@ -3504,6 +3505,10 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {
35043505 // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth
35053506 // is an integer constant. Masking with BitWidth-1 comes free on some
35063507 // hardware as part of the shift instruction.
3508+
3509+ // Drop range attributes and re-infer them in the next iteration.
3510+ cast<Instruction>(Ctlz)->dropPoisonGeneratingAnnotations ();
3511+ IC.addToWorklist (cast<Instruction>(Ctlz));
35073512 Value *Neg = Builder.CreateNeg (Ctlz);
35083513 Value *Masked =
35093514 Builder.CreateAnd (Neg, ConstantInt::get (SelType, BitWidth - 1 ));
@@ -4147,7 +4152,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
41474152 if (sinkNotIntoOtherHandOfLogicalOp (SI))
41484153 return &SI;
41494154
4150- if (Instruction *I = foldBitCeil (SI, Builder))
4155+ if (Instruction *I = foldBitCeil (SI, Builder, * this ))
41514156 return I;
41524157
41534158 if (Instruction *I = foldSelectToCmp (SI))
0 commit comments