Skip to content

Commit 3ffb79c

Browse files
committed
[InstCombine] Drop range attributes in foldBitCeil
1 parent 7c48f4c commit 3ffb79c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

llvm/test/Transforms/InstCombine/bit_ceil.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ define i32 @pr91691_keep_nsw(i32 %0) {
322322

323323
define i32 @test_drop_range_attr(i32 %x) {
324324
; CHECK-LABEL: @test_drop_range_attr(
325-
; CHECK-NEXT: [[CTLZ:%.*]] = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 false)
325+
; CHECK-NEXT: [[CTLZ:%.*]] = call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 false)
326326
; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i32 0, [[CTLZ]]
327327
; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 31
328328
; CHECK-NEXT: [[SEL:%.*]] = shl nuw i32 1, [[TMP2]]

0 commit comments

Comments
 (0)