diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-06-02 16:27:44 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-06-02 16:27:44 +0000 |
commit | bbc6d60677c65aa8073c15b89aae353b192a472b (patch) | |
tree | 05a11e1ebc58f842e9c6badb54f4e38950a9983c /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | 51f19b9ee1d8469caeeeaf2b1774663ee50c6d69 (diff) | |
download | bcm5719-llvm-bbc6d60677c65aa8073c15b89aae353b192a472b.tar.gz bcm5719-llvm-bbc6d60677c65aa8073c15b89aae353b192a472b.zip |
[InstCombine] call simplify before trying vector folds
As noted in the review thread for rL333782, we could have
made a bug harder to hit if we were simplifying instructions
before trying other folds.
The shuffle transform in question isn't ever a simplification;
it's just a canonicalization. So I've renamed that to make that
clearer.
This is NFCI at this point, but I've regenerated the test file
to show the cosmetic value naming difference of using
instcombine's RAUW vs. the builder.
Possible follow-ups:
1. Move reassociation folds after simplifies too.
2. Refactor common code; we shouldn't have so much repetition.
llvm-svn: 333820
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 420a28bfdf2..15c412a76bb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -128,13 +128,12 @@ static Constant *getLogBase2(Type *Ty, Constant *C) { Instruction *InstCombiner::visitMul(BinaryOperator &I) { bool Changed = SimplifyAssociativeOrCommutative(I); Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifyMulInst(Op0, Op1, SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + if (Value *V = SimplifyUsingDistributiveLaws(I)) return replaceInstUsesWith(I, V); @@ -409,14 +408,13 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { Instruction *InstCombiner::visitFMul(BinaryOperator &I) { bool Changed = SimplifyAssociativeOrCommutative(I); Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifyFMulInst(Op0, Op1, I.getFastMathFlags(), SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + if (Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I)) return FoldedMul; @@ -939,13 +937,12 @@ static Instruction *narrowUDivURem(BinaryOperator &I, Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifyUDivInst(Op0, Op1, SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + // Handle the integer div common cases if (Instruction *Common = commonIDivTransforms(I)) return Common; @@ -1008,13 +1005,12 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifySDivInst(Op0, Op1, SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + // Handle the integer div common cases if (Instruction *Common = commonIDivTransforms(I)) return Common; @@ -1152,14 +1148,13 @@ static Instruction *foldFDivConstantDividend(BinaryOperator &I) { Instruction *InstCombiner::visitFDiv(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifyFDivInst(Op0, Op1, I.getFastMathFlags(), SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + if (Instruction *R = foldFDivConstantDivisor(I)) return R; @@ -1282,13 +1277,12 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) { Instruction *InstCombiner::visitURem(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifyURemInst(Op0, Op1, SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + if (Instruction *common = commonIRemTransforms(I)) return common; @@ -1321,13 +1315,12 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) { Instruction *InstCombiner::visitSRem(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifySRemInst(Op0, Op1, SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + // Handle the integer rem common cases if (Instruction *Common = commonIRemTransforms(I)) return Common; @@ -1394,13 +1387,12 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) { Instruction *InstCombiner::visitFRem(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - - if (Value *V = SimplifyVectorOp(I)) - return replaceInstUsesWith(I, V); - if (Value *V = SimplifyFRemInst(Op0, Op1, I.getFastMathFlags(), SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + if (Instruction *X = foldShuffledBinop(I)) + return X; + return nullptr; } |