@@ -3466,7 +3466,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
3466
3466
// Note that the select is optimized away while the shift count is masked with
3467
3467
// 31. We handle some variations of the input operand like std::bit_ceil(X +
3468
3468
// 1).
3469
- static Instruction *foldBitCeil (SelectInst &SI, IRBuilderBase &Builder) {
3469
+ static Instruction *foldBitCeil (SelectInst &SI, IRBuilderBase &Builder,
3470
+ InstCombinerImpl &IC) {
3470
3471
Type *SelType = SI.getType ();
3471
3472
unsigned BitWidth = SelType->getScalarSizeInBits ();
3472
3473
@@ -3501,6 +3502,10 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {
3501
3502
// single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth
3502
3503
// is an integer constant. Masking with BitWidth-1 comes free on some
3503
3504
// 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));
3504
3509
Value *Neg = Builder.CreateNeg (Ctlz);
3505
3510
Value *Masked =
3506
3511
Builder.CreateAnd (Neg, ConstantInt::get (SelType, BitWidth - 1 ));
@@ -4148,7 +4153,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
4148
4153
if (sinkNotIntoOtherHandOfLogicalOp (SI))
4149
4154
return &SI;
4150
4155
4151
- if (Instruction *I = foldBitCeil (SI, Builder))
4156
+ if (Instruction *I = foldBitCeil (SI, Builder, * this ))
4152
4157
return I;
4153
4158
4154
4159
if (Instruction *I = foldSelectToCmp (SI))
0 commit comments