[llvm-branch-commits] [llvm] 0168917 - [ConstantFold] Remove redundant handling for casts of null (NFCI)

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 3 13:41:05 PDT 2023


Author: Nikita Popov
Date: 2023-11-03T11:41:14+01:00
New Revision: 01689175251f2624fb9d077666657aa21e3f7850

URL: https://github.com/llvm/llvm-project/commit/01689175251f2624fb9d077666657aa21e3f7850
DIFF: https://github.com/llvm/llvm-project/commit/01689175251f2624fb9d077666657aa21e3f7850.diff

LOG: [ConstantFold] Remove redundant handling for casts of null (NFCI)

ConstantFoldCastInstruction() has generic handling for null values
at the top. No need to repeat it for inttoptr and ptrtoint.

Added: 
    

Modified: 
    llvm/lib/IR/ConstantFold.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index d51e9c67592eb95..91bb5b6149f4877 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -301,16 +301,6 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
       return ConstantInt::get(FPC->getContext(), IntVal);
     }
     return nullptr; // Can't fold.
-  case Instruction::IntToPtr:   //always treated as unsigned
-    if (V->isNullValue())       // Is it an integral null value?
-      return ConstantPointerNull::get(cast<PointerType>(DestTy));
-    return nullptr;                   // Other pointer types cannot be casted
-  case Instruction::PtrToInt:   // always treated as unsigned
-    // Is it a null pointer value?
-    if (V->isNullValue())
-      return ConstantInt::get(DestTy, 0);
-    // Other pointer types cannot be casted
-    return nullptr;
   case Instruction::UIToFP:
   case Instruction::SIToFP:
     if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
@@ -359,6 +349,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
   case Instruction::BitCast:
     return FoldBitCast(V, DestTy);
   case Instruction::AddrSpaceCast:
+  case Instruction::IntToPtr:
+  case Instruction::PtrToInt:
     return nullptr;
   }
 }


        


More information about the llvm-branch-commits mailing list