mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-18 11:24:01 +00:00
Check for all known bits on ret in InstCombine
From a combination of @llvm.assume calls (and perhaps through other means, such as range metadata), it is possible that all bits of a return value might be known. Previously, InstCombine did not check for this (which is understandable given assumptions of constant propagation), but means that we'd miss simple cases where assumptions are involved. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217346 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -2004,7 +2004,25 @@ Instruction *InstCombiner::visitFree(CallInst &FI) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitReturnInst(ReturnInst &RI) {
|
||||
if (RI.getNumOperands() == 0) // ret void
|
||||
return nullptr;
|
||||
|
||||
Value *ResultOp = RI.getOperand(0);
|
||||
Type *VTy = ResultOp->getType();
|
||||
if (!VTy->isIntegerTy())
|
||||
return nullptr;
|
||||
|
||||
// There might be assume intrinsics dominating this return that completely
|
||||
// determine the value. If so, constant fold it.
|
||||
unsigned BitWidth = VTy->getPrimitiveSizeInBits();
|
||||
APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
|
||||
computeKnownBits(ResultOp, KnownZero, KnownOne, 0, &RI);
|
||||
if ((KnownZero|KnownOne).isAllOnesValue())
|
||||
RI.setOperand(0, Constant::getIntegerValue(VTy, KnownOne));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitBranchInst(BranchInst &BI) {
|
||||
// Change br (not X), label True, label False to: br X, label False, True
|
||||
|
Reference in New Issue
Block a user