|
22 | 22 | #include "llvm/Analysis/ConstantFolding.h"
|
23 | 23 | #include "llvm/Analysis/InstructionSimplify.h"
|
24 | 24 | #include "llvm/Analysis/LoopInfo.h"
|
| 25 | +#include "llvm/Analysis/MemoryBuiltins.h" |
25 | 26 | #include "llvm/Analysis/OptimizationRemarkEmitter.h"
|
26 | 27 | #include "llvm/Analysis/ProfileSummaryInfo.h"
|
27 | 28 | #include "llvm/Analysis/TargetLibraryInfo.h"
|
@@ -419,6 +420,7 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
|
419 | 420 | bool simplifyCallSite(Function *F, CallBase &Call);
|
420 | 421 | bool simplifyInstruction(Instruction &I);
|
421 | 422 | bool simplifyIntrinsicCallIsConstant(CallBase &CB);
|
| 423 | + bool simplifyIntrinsicCallObjectSize(CallBase &CB); |
422 | 424 | ConstantInt *stripAndComputeInBoundsConstantOffsets(Value *&V);
|
423 | 425 |
|
424 | 426 | /// Return true if the given argument to the function being considered for
|
@@ -1602,6 +1604,20 @@ bool CallAnalyzer::simplifyIntrinsicCallIsConstant(CallBase &CB) {
|
1602 | 1604 | return true;
|
1603 | 1605 | }
|
1604 | 1606 |
|
| 1607 | +bool CallAnalyzer::simplifyIntrinsicCallObjectSize(CallBase &CB) { |
| 1608 | + // As per the langref, "The fourth argument to llvm.objectsize determines if |
| 1609 | + // the value should be evaluated at runtime." |
| 1610 | + if(cast<ConstantInt>(CB.getArgOperand(3))->isOne()) |
| 1611 | + return false; |
| 1612 | + |
| 1613 | + Value *V = lowerObjectSizeCall(&cast<IntrinsicInst>(CB), DL, nullptr, |
| 1614 | + /*MustSucceed=*/true); |
| 1615 | + Constant *C = dyn_cast_or_null<Constant>(V); |
| 1616 | + if (C) |
| 1617 | + SimplifiedValues[&CB] = C; |
| 1618 | + return C; |
| 1619 | +} |
| 1620 | + |
1605 | 1621 | bool CallAnalyzer::visitBitCast(BitCastInst &I) {
|
1606 | 1622 | // Propagate constants through bitcasts.
|
1607 | 1623 | if (simplifyInstruction(I))
|
@@ -2214,6 +2230,8 @@ bool CallAnalyzer::visitCallBase(CallBase &Call) {
|
2214 | 2230 | return true;
|
2215 | 2231 | case Intrinsic::is_constant:
|
2216 | 2232 | return simplifyIntrinsicCallIsConstant(Call);
|
| 2233 | + case Intrinsic::objectsize: |
| 2234 | + return simplifyIntrinsicCallObjectSize(Call); |
2217 | 2235 | }
|
2218 | 2236 | }
|
2219 | 2237 |
|
|
0 commit comments