summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/TypePromotion.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index d78589c4a05..000cd366dd6 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -46,7 +46,7 @@
using namespace llvm;
static cl::opt<bool>
-DisablePromotion("disable-type-promotion", cl::Hidden, cl::init(true),
+DisablePromotion("disable-type-promotion", cl::Hidden, cl::init(false),
cl::desc("Disable type promotion pass"));
// The goal of this pass is to enable more efficient code generation for
@@ -902,16 +902,34 @@ bool TypePromotion::TryToPromote(Value *V, unsigned PromotedWidth) {
for (auto *I : CurrentVisited)
I->dump();
);
+
+ // Check that promoting this at the IR level is most likely beneficial. It's
+ // more likely if we're operating over multiple blocks and handling wrapping
+ // instructions.
unsigned ToPromote = 0;
+ unsigned NonFreeArgs = 0;
+ SmallPtrSet<BasicBlock*, 4> Blocks;
for (auto *V : CurrentVisited) {
- if (Sources.count(V))
+ if (auto *I = dyn_cast<Instruction>(V))
+ Blocks.insert(I->getParent());
+
+ if (Sources.count(V)) {
+ if (auto *Arg = dyn_cast<Argument>(V)) {
+ if (!Arg->hasZExtAttr() && !Arg->hasSExtAttr())
+ ++NonFreeArgs;
+ }
continue;
+ }
+
if (Sinks.count(cast<Instruction>(V)))
continue;
+
++ToPromote;
}
- if (ToPromote < 2)
+ // DAG optimisations should be able to handle these cases better, especially
+ // for function arguments.
+ if (ToPromote < 2 || (Blocks.size() == 1 && (NonFreeArgs > SafeWrap.size())))
return false;
Promoter->Mutate(OrigTy, PromotedWidth, CurrentVisited, Sources, Sinks,
OpenPOWER on IntegriCloud