-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[VectorCombine] Use InstSimplifyFolder to simplify instrs on creation. #146350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
27f7c6e
b60022d
4c30369
e63f037
2c39937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,7 @@ | |||||||||||||||||
#include "llvm/Analysis/BasicAliasAnalysis.h" | ||||||||||||||||||
#include "llvm/Analysis/ConstantFolding.h" | ||||||||||||||||||
#include "llvm/Analysis/GlobalsModRef.h" | ||||||||||||||||||
#include "llvm/Analysis/InstSimplifyFolder.h" | ||||||||||||||||||
#include "llvm/Analysis/Loads.h" | ||||||||||||||||||
#include "llvm/Analysis/TargetTransformInfo.h" | ||||||||||||||||||
#include "llvm/Analysis/ValueTracking.h" | ||||||||||||||||||
|
@@ -72,14 +73,15 @@ class VectorCombine { | |||||||||||||||||
const DominatorTree &DT, AAResults &AA, AssumptionCache &AC, | ||||||||||||||||||
const DataLayout *DL, TTI::TargetCostKind CostKind, | ||||||||||||||||||
bool TryEarlyFoldsOnly) | ||||||||||||||||||
: F(F), Builder(F.getContext()), TTI(TTI), DT(DT), AA(AA), AC(AC), DL(DL), | ||||||||||||||||||
CostKind(CostKind), TryEarlyFoldsOnly(TryEarlyFoldsOnly) {} | ||||||||||||||||||
: F(F), Builder(F.getContext(), InstSimplifyFolder(*DL)), TTI(TTI), | ||||||||||||||||||
DT(DT), AA(AA), AC(AC), DL(DL), CostKind(CostKind), | ||||||||||||||||||
TryEarlyFoldsOnly(TryEarlyFoldsOnly) {} | ||||||||||||||||||
|
||||||||||||||||||
bool run(); | ||||||||||||||||||
|
||||||||||||||||||
private: | ||||||||||||||||||
Function &F; | ||||||||||||||||||
IRBuilder<> Builder; | ||||||||||||||||||
IRBuilder<InstSimplifyFolder> Builder; | ||||||||||||||||||
const TargetTransformInfo &TTI; | ||||||||||||||||||
const DominatorTree &DT; | ||||||||||||||||||
AAResults &AA; | ||||||||||||||||||
|
@@ -529,7 +531,7 @@ bool VectorCombine::isExtractExtractCheap(ExtractElementInst *Ext0, | |||||||||||||||||
/// Create a shuffle that translates (shifts) 1 element from the input vector | ||||||||||||||||||
/// to a new element location. | ||||||||||||||||||
static Value *createShiftShuffle(Value *Vec, unsigned OldIndex, | ||||||||||||||||||
unsigned NewIndex, IRBuilder<> &Builder) { | ||||||||||||||||||
unsigned NewIndex, IRBuilderBase &Builder) { | ||||||||||||||||||
// The shuffle mask is poison except for 1 lane that is being translated | ||||||||||||||||||
// to the new element index. Example for OldIndex == 2 and NewIndex == 0: | ||||||||||||||||||
// ShufMask = { 2, poison, poison, poison } | ||||||||||||||||||
|
@@ -545,7 +547,7 @@ static Value *createShiftShuffle(Value *Vec, unsigned OldIndex, | |||||||||||||||||
/// unnecessary instructions. | ||||||||||||||||||
static ExtractElementInst *translateExtract(ExtractElementInst *ExtElt, | ||||||||||||||||||
unsigned NewIndex, | ||||||||||||||||||
IRBuilder<> &Builder) { | ||||||||||||||||||
IRBuilderBase &Builder) { | ||||||||||||||||||
// Shufflevectors can only be created for fixed-width vectors. | ||||||||||||||||||
Value *X = ExtElt->getVectorOperand(); | ||||||||||||||||||
if (!isa<FixedVectorType>(X->getType())) | ||||||||||||||||||
|
@@ -1459,10 +1461,12 @@ bool VectorCombine::foldBinopOfReductions(Instruction &I) { | |||||||||||||||||
LLVM_DEBUG(dbgs() << "Found two mergeable reductions: " << I | ||||||||||||||||||
<< "\n OldCost: " << OldCost << " vs NewCost: " << NewCost | ||||||||||||||||||
<< "\n"); | ||||||||||||||||||
Value *VectorBO = Builder.CreateBinOp(BinOpOpc, V0, V1); | ||||||||||||||||||
if (auto *PDInst = dyn_cast<PossiblyDisjointInst>(&I)) | ||||||||||||||||||
if (auto *PDVectorBO = dyn_cast<PossiblyDisjointInst>(VectorBO)) | ||||||||||||||||||
PDVectorBO->setIsDisjoint(PDInst->isDisjoint()); | ||||||||||||||||||
Value *VectorBO; | ||||||||||||||||||
if (BinOpOpc == Instruction::Or) | ||||||||||||||||||
VectorBO = Builder.CreateOr(V0, V1, "", | ||||||||||||||||||
cast<PossiblyDisjointInst>(I).isDisjoint()); | ||||||||||||||||||
else | ||||||||||||||||||
VectorBO = Builder.CreateBinOp(BinOpOpc, V0, V1); | ||||||||||||||||||
Comment on lines
+1465
to
+1469
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Better not to rely on just Or being PossiblyDisjoint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I added |
||||||||||||||||||
|
||||||||||||||||||
Instruction *Rdx = Builder.CreateIntrinsic(ReductionIID, {VTy}, {VectorBO}); | ||||||||||||||||||
replaceValue(I, *Rdx); | ||||||||||||||||||
|
@@ -1519,7 +1523,7 @@ class ScalarizationResult { | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/// Freeze the ToFreeze and update the use in \p User to use it. | ||||||||||||||||||
void freeze(IRBuilder<> &Builder, Instruction &UserI) { | ||||||||||||||||||
void freeze(IRBuilderBase &Builder, Instruction &UserI) { | ||||||||||||||||||
assert(isSafeWithFreeze() && | ||||||||||||||||||
"should only be used when freezing is required"); | ||||||||||||||||||
assert(is_contained(ToFreeze->users(), &UserI) && | ||||||||||||||||||
|
@@ -2617,7 +2621,7 @@ static Value *generateNewInstTree(ArrayRef<InstLane> Item, FixedVectorType *Ty, | |||||||||||||||||
const SmallPtrSet<Use *, 4> &IdentityLeafs, | ||||||||||||||||||
const SmallPtrSet<Use *, 4> &SplatLeafs, | ||||||||||||||||||
const SmallPtrSet<Use *, 4> &ConcatLeafs, | ||||||||||||||||||
IRBuilder<> &Builder, | ||||||||||||||||||
IRBuilderBase &Builder, | ||||||||||||||||||
const TargetTransformInfo *TTI) { | ||||||||||||||||||
auto [FrontU, FrontLane] = Item.front(); | ||||||||||||||||||
|
||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to introduce a CreateDisjoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added CreatebinOpDisjoint instead, similar to CreateBinOpFMF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your previous code was better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically because there is only a single operation that can be disjoint, which is or, so it doesn't make much sense to pretend otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to defer to @nikic's judgement: you can ignore my suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, reverted the change, thanks