summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDaniel Berlin <dberlin@dberlin.org>2017-02-12 22:25:20 +0000
committerDaniel Berlin <dberlin@dberlin.org>2017-02-12 22:25:20 +0000
commit86eab15f2ba19e4327e18aaacee833d099ecc5b8 (patch)
tree3cd16888f53ea7f492e0e73cdb9e8a36888b8906 /llvm
parentdbe8264c93b6aebca35a3d5b6dbc74214af2f52f (diff)
downloadbcm5719-llvm-86eab15f2ba19e4327e18aaacee833d099ecc5b8.tar.gz
bcm5719-llvm-86eab15f2ba19e4327e18aaacee833d099ecc5b8.zip
NewGVN: Apply the fast math flags fix in r267113 to NewGVN as well.
llvm-svn: 294922
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Scalar/NewGVN.cpp49
-rw-r--r--llvm/test/Transforms/NewGVN/flags.ll1
2 files changed, 26 insertions, 24 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 38e4a30e496..25455c75b4e 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -2059,31 +2059,34 @@ void NewGVN::convertDenseToLoadsAndStores(
}
static void patchReplacementInstruction(Instruction *I, Value *Repl) {
+ auto *ReplInst = dyn_cast<Instruction>(Repl);
+ if (!ReplInst)
+ return;
+
// Patch the replacement so that it is not more restrictive than the value
// being replaced.
- auto *Op = dyn_cast<BinaryOperator>(I);
- auto *ReplOp = dyn_cast<BinaryOperator>(Repl);
-
- if (Op && ReplOp)
- ReplOp->andIRFlags(Op);
-
- if (auto *ReplInst = dyn_cast<Instruction>(Repl)) {
- // FIXME: If both the original and replacement value are part of the
- // same control-flow region (meaning that the execution of one
- // guarentees the executation of the other), then we can combine the
- // noalias scopes here and do better than the general conservative
- // answer used in combineMetadata().
-
- // In general, GVN unifies expressions over different control-flow
- // regions, and so we need a conservative combination of the noalias
- // scopes.
- unsigned KnownIDs[] = {
- LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
- LLVMContext::MD_noalias, LLVMContext::MD_range,
- LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load,
- LLVMContext::MD_invariant_group};
- combineMetadata(ReplInst, I, KnownIDs);
- }
+ // Note that if 'I' is a load being replaced by some operation,
+ // for example, by an arithmetic operation, then andIRFlags()
+ // would just erase all math flags from the original arithmetic
+ // operation, which is clearly not wanted and not needed.
+ if (!isa<LoadInst>(I))
+ ReplInst->andIRFlags(I);
+
+ // FIXME: If both the original and replacement value are part of the
+ // same control-flow region (meaning that the execution of one
+ // guarantees the execution of the other), then we can combine the
+ // noalias scopes here and do better than the general conservative
+ // answer used in combineMetadata().
+
+ // In general, GVN unifies expressions over different control-flow
+ // regions, and so we need a conservative combination of the noalias
+ // scopes.
+ static const unsigned KnownIDs[] = {
+ LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
+ LLVMContext::MD_noalias, LLVMContext::MD_range,
+ LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load,
+ LLVMContext::MD_invariant_group};
+ combineMetadata(ReplInst, I, KnownIDs);
}
static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl) {
diff --git a/llvm/test/Transforms/NewGVN/flags.ll b/llvm/test/Transforms/NewGVN/flags.ll
index d03edd6776c..e849ae2afb6 100644
--- a/llvm/test/Transforms/NewGVN/flags.ll
+++ b/llvm/test/Transforms/NewGVN/flags.ll
@@ -1,4 +1,3 @@
-; XFAIL: *
; RUN: opt -newgvn -S < %s | FileCheck %s
declare void @use(i1)
OpenPOWER on IntegriCloud