[llvm] 12d6832 - [SCCP] Skip bitcasts entirely

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 8 07:11:16 PDT 2024


Author: Nikita Popov
Date: 2024-07-08T16:10:58+02:00
New Revision: 12d6832d86156904aecc10e8612bd77b66aeef51

URL: https://github.com/llvm/llvm-project/commit/12d6832d86156904aecc10e8612bd77b66aeef51
DIFF: https://github.com/llvm/llvm-project/commit/12d6832d86156904aecc10e8612bd77b66aeef51.diff

LOG: [SCCP] Skip bitcasts entirely

The only bitcasts the existing code might be able to handle are
bitcasts between iN and <1 x iN>. Don't bother.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SCCPSolver.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index 4f36bac11e34b7..db0d40b317d179 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1295,24 +1295,16 @@ void SCCPInstVisitor::visitCastInst(CastInst &I) {
       return (void)markConstant(&I, C);
   }
 
-  if (I.getDestTy()->isIntegerTy() && I.getSrcTy()->isIntOrIntVectorTy()) {
+  // Ignore bitcasts, as they may change the number of vector elements.
+  if (I.getDestTy()->isIntegerTy() && I.getSrcTy()->isIntOrIntVectorTy() &&
+      I.getOpcode() != Instruction::BitCast) {
     auto &LV = getValueState(&I);
     ConstantRange OpRange =
         getConstantRange(OpSt, I.getSrcTy(), /*UndefAllowed=*/false);
 
     Type *DestTy = I.getDestTy();
-    // Vectors where all elements have the same known constant range are treated
-    // as a single constant range in the lattice. When bitcasting such vectors,
-    // there is a mis-match between the width of the lattice value (single
-    // constant range) and the original operands (vector). Go to overdefined in
-    // that case.
-    if (I.getOpcode() == Instruction::BitCast &&
-        I.getOperand(0)->getType()->isVectorTy() &&
-        OpRange.getBitWidth() < DL.getTypeSizeInBits(DestTy))
-      return (void)markOverdefined(&I);
-
     ConstantRange Res =
-        OpRange.castOp(I.getOpcode(), DL.getTypeSizeInBits(DestTy));
+        OpRange.castOp(I.getOpcode(), DestTy->getScalarSizeInBits());
     mergeInValue(LV, &I, ValueLatticeElement::getRange(Res));
   } else
     markOverdefined(&I);


        


More information about the llvm-commits mailing list