[llvm] 6631907 - [InstCombine] use isKnownNonNegative to reduce code duplication; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 14:13:36 PDT 2022


Author: Sanjay Patel
Date: 2022-04-25T17:13:29-04:00
New Revision: 6631907ad20f74eec47fee461f90a21531ec7822

URL: https://github.com/llvm/llvm-project/commit/6631907ad20f74eec47fee461f90a21531ec7822
DIFF: https://github.com/llvm/llvm-project/commit/6631907ad20f74eec47fee461f90a21531ec7822.diff

LOG: [InstCombine] use isKnownNonNegative to reduce code duplication; NFC

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.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index e27b659f2dfb9..9a89aa557258a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -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.


        


More information about the llvm-commits mailing list