mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
[InstSimplify] try constant folding intrinsics before general simplifications
This matches the behavior of simplify calls for regular opcodes - rely on ConstantFolding before spending time on folds with variables. I am not aware of any diffs from this re-ordering currently, but there was potential for unintended behavior from the min/max intrinsics because that code is implicitly assuming that only 1 of the input operands is constant.
This commit is contained in:
parent
220154b160
commit
26020de8d8
@ -5484,28 +5484,9 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *llvm::SimplifyCall(CallBase *Call, const SimplifyQuery &Q) {
|
static Value *tryConstantFoldCall(CallBase *Call, const SimplifyQuery &Q) {
|
||||||
Value *Callee = Call->getCalledOperand();
|
auto *F = dyn_cast<Function>(Call->getCalledOperand());
|
||||||
|
if (!F || !canConstantFoldCallTo(Call, F))
|
||||||
// musttail calls can only be simplified if they are also DCEd.
|
|
||||||
// As we can't guarantee this here, don't simplify them.
|
|
||||||
if (Call->isMustTailCall())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// call undef -> undef
|
|
||||||
// call null -> undef
|
|
||||||
if (isa<UndefValue>(Callee) || isa<ConstantPointerNull>(Callee))
|
|
||||||
return UndefValue::get(Call->getType());
|
|
||||||
|
|
||||||
Function *F = dyn_cast<Function>(Callee);
|
|
||||||
if (!F)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
if (F->isIntrinsic())
|
|
||||||
if (Value *Ret = simplifyIntrinsic(Call, Q))
|
|
||||||
return Ret;
|
|
||||||
|
|
||||||
if (!canConstantFoldCallTo(Call, F))
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
SmallVector<Constant *, 4> ConstantArgs;
|
SmallVector<Constant *, 4> ConstantArgs;
|
||||||
@ -5524,6 +5505,29 @@ Value *llvm::SimplifyCall(CallBase *Call, const SimplifyQuery &Q) {
|
|||||||
return ConstantFoldCall(Call, F, ConstantArgs, Q.TLI);
|
return ConstantFoldCall(Call, F, ConstantArgs, Q.TLI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value *llvm::SimplifyCall(CallBase *Call, const SimplifyQuery &Q) {
|
||||||
|
// musttail calls can only be simplified if they are also DCEd.
|
||||||
|
// As we can't guarantee this here, don't simplify them.
|
||||||
|
if (Call->isMustTailCall())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// call undef -> undef
|
||||||
|
// call null -> undef
|
||||||
|
Value *Callee = Call->getCalledOperand();
|
||||||
|
if (isa<UndefValue>(Callee) || isa<ConstantPointerNull>(Callee))
|
||||||
|
return UndefValue::get(Call->getType());
|
||||||
|
|
||||||
|
if (Value *V = tryConstantFoldCall(Call, Q))
|
||||||
|
return V;
|
||||||
|
|
||||||
|
auto *F = dyn_cast<Function>(Callee);
|
||||||
|
if (F && F->isIntrinsic())
|
||||||
|
if (Value *Ret = simplifyIntrinsic(Call, Q))
|
||||||
|
return Ret;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/// Given operands for a Freeze, see if we can fold the result.
|
/// Given operands for a Freeze, see if we can fold the result.
|
||||||
static Value *SimplifyFreezeInst(Value *Op0, const SimplifyQuery &Q) {
|
static Value *SimplifyFreezeInst(Value *Op0, const SimplifyQuery &Q) {
|
||||||
// Use a utility function defined in ValueTracking.
|
// Use a utility function defined in ValueTracking.
|
||||||
|
Loading…
Reference in New Issue
Block a user