Skip to content

Commit 0168917

Browse files
committed
[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.
1 parent d49a893 commit 0168917

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,6 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
301301
return ConstantInt::get(FPC->getContext(), IntVal);
302302
}
303303
return nullptr; // Can't fold.
304-
case Instruction::IntToPtr: //always treated as unsigned
305-
if (V->isNullValue()) // Is it an integral null value?
306-
return ConstantPointerNull::get(cast<PointerType>(DestTy));
307-
return nullptr; // Other pointer types cannot be casted
308-
case Instruction::PtrToInt: // always treated as unsigned
309-
// Is it a null pointer value?
310-
if (V->isNullValue())
311-
return ConstantInt::get(DestTy, 0);
312-
// Other pointer types cannot be casted
313-
return nullptr;
314304
case Instruction::UIToFP:
315305
case Instruction::SIToFP:
316306
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
@@ -359,6 +349,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
359349
case Instruction::BitCast:
360350
return FoldBitCast(V, DestTy);
361351
case Instruction::AddrSpaceCast:
352+
case Instruction::IntToPtr:
353+
case Instruction::PtrToInt:
362354
return nullptr;
363355
}
364356
}

0 commit comments

Comments
 (0)