Skip to content

Commit

Permalink
[InstCombine] use isKnownNonNegative to reduce code duplication; NFC
Browse files Browse the repository at this point in the history
We may be able to make the ValueTracking wrapper smarter
in the future (for example, analyze a simple recurrence),
so this will automatically benefit if that happens.
  • Loading branch information
rotateright committed Apr 25, 2022
1 parent b3e8e43 commit 6631907
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Expand Up @@ -1503,10 +1503,8 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &CI) {
unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
unsigned DestBitSize = DestTy->getScalarSizeInBits();

// If we know that the value being extended is positive, we can use a zext
// instead.
KnownBits Known = computeKnownBits(Src, 0, &CI);
if (Known.isNonNegative())
// If the value being extended is zero or positive, use a zext instead.
if (isKnownNonNegative(Src, DL, 0, &AC, &CI, &DT))
return CastInst::Create(Instruction::ZExt, Src, DestTy);

// Try to extend the entire expression tree to the wide destination type.
Expand Down

0 comments on commit 6631907

Please sign in to comment.