@@ -3466,7 +3466,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
34663466// Note that the select is optimized away while the shift count is masked with
34673467// 31. We handle some variations of the input operand like std::bit_ceil(X +
34683468// 1).
3469- static Instruction *foldBitCeil (SelectInst &SI, IRBuilderBase &Builder) {
3469+ static Instruction *foldBitCeil (SelectInst &SI, IRBuilderBase &Builder,
3470+ InstCombinerImpl &IC) {
34703471 Type *SelType = SI.getType ();
34713472 unsigned BitWidth = SelType->getScalarSizeInBits ();
34723473
@@ -3501,6 +3502,10 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {
35013502 // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth
35023503 // is an integer constant. Masking with BitWidth-1 comes free on some
35033504 // hardware as part of the shift instruction.
3505+
3506+ // Drop range attributes and re-infer them in the next iteration.
3507+ cast<Instruction>(Ctlz)->dropPoisonGeneratingAnnotations ();
3508+ IC.addToWorklist (cast<Instruction>(Ctlz));
35043509 Value *Neg = Builder.CreateNeg (Ctlz);
35053510 Value *Masked =
35063511 Builder.CreateAnd (Neg, ConstantInt::get (SelType, BitWidth - 1 ));
@@ -4148,7 +4153,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
41484153 if (sinkNotIntoOtherHandOfLogicalOp (SI))
41494154 return &SI;
41504155
4151- if (Instruction *I = foldBitCeil (SI, Builder))
4156+ if (Instruction *I = foldBitCeil (SI, Builder, * this ))
41524157 return I;
41534158
41544159 if (Instruction *I = foldSelectToCmp (SI))
0 commit comments