[llvm] f93cd56 - [BPI] Avoid ConstantExpr::get()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 4 07:04:34 PDT 2022
Author: Nikita Popov
Date: 2022-07-04T16:04:26+02:00
New Revision: f93cd56262d1db6e00acf81b5fa4aff6c837a07b
URL: https://github.com/llvm/llvm-project/commit/f93cd56262d1db6e00acf81b5fa4aff6c837a07b
DIFF: https://github.com/llvm/llvm-project/commit/f93cd56262d1db6e00acf81b5fa4aff6c837a07b.diff
LOG: [BPI] Avoid ConstantExpr::get()
Use ConstantFoldBinaryOpOperands() instead, to prepare for the case
where not all binary operators have a constant expression form.
I believe this code actually intended to set OnlyIfReduced=true,
however ConstantExpr::get() actually accepts a Flags argument at
that position (and OnlyIfReducedTy as the next argument), so this
ended up creating a constant expression with some random flag
(probably exact or nuw depending on which).
Added:
Modified:
llvm/lib/Analysis/BranchProbabilityInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 1d880424e55c..87863db20814 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
@@ -629,9 +630,10 @@ computeUnlikelySuccessors(const BasicBlock *BB, Loop *L,
if (!CmpLHSConst || !llvm::is_contained(successors(BB), B))
continue;
// First collapse InstChain
+ const DataLayout &DL = BB->getModule()->getDataLayout();
for (Instruction *I : llvm::reverse(InstChain)) {
- CmpLHSConst = ConstantExpr::get(I->getOpcode(), CmpLHSConst,
- cast<Constant>(I->getOperand(1)), true);
+ CmpLHSConst = ConstantFoldBinaryOpOperands(
+ I->getOpcode(), CmpLHSConst, cast<Constant>(I->getOperand(1)), DL);
if (!CmpLHSConst)
break;
}
More information about the llvm-commits
mailing list