summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-06-21 23:56:59 +0000
committerSanjay Patel <spatel@rotateright.com>2018-06-21 23:56:59 +0000
commit4784e1506e37f80efcfed000ee2879260a1cd576 (patch)
tree46e77da1686b2c53ba9519aa3e4258bf79016c70 /llvm/lib/Transforms
parent23408c25f3c3bc5e80effe3d4750392f96d397ad (diff)
downloadbcm5719-llvm-4784e1506e37f80efcfed000ee2879260a1cd576.tar.gz
bcm5719-llvm-4784e1506e37f80efcfed000ee2879260a1cd576.zip
[InstCombine] fix shuffle-of-binops bug
With non-commutative binops, we could be using the same variable value as operand 0 in 1 binop and operand 1 in the other, so we have to check for that possibility and bail out. llvm-svn: 335312
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index d8546c7b89a..01b1f4cdf3c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -1166,6 +1166,13 @@ static Instruction *foldSelectShuffles(ShuffleVectorInst &Shuf) {
if (isa<Constant>(X))
return nullptr;
+ // Constant operands must be on the same side of each binop. We can't fold:
+ // shuffle (sdiv X, C0), (sdiv C1, X).
+ bool B00IsConst = isa<Constant>(B0->getOperand(0));
+ bool B10IsConst = isa<Constant>(B1->getOperand(0));
+ if (B00IsConst != B10IsConst)
+ return nullptr;
+
// Remove a binop and the shuffle by rearranging the constant:
// shuffle (op X, C0), (op X, C1), M --> op X, C'
// shuffle (op C0, X), (op C1, X), M --> op C', X
@@ -1178,8 +1185,7 @@ static Instruction *foldSelectShuffles(ShuffleVectorInst &Shuf) {
NewC = getSafeVectorConstantForIntDivRem(NewC);
BinaryOperator::BinaryOps Opc = B0->getOpcode();
- bool Op0IsConst = isa<Constant>(B0->getOperand(0));
- Instruction *NewBO = Op0IsConst ? BinaryOperator::Create(Opc, NewC, X) :
+ Instruction *NewBO = B00IsConst ? BinaryOperator::Create(Opc, NewC, X) :
BinaryOperator::Create(Opc, X, NewC);
// Flags are intersected from the 2 source binops.
OpenPOWER on IntegriCloud