summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-10-23 14:07:39 +0000
committerSanjay Patel <spatel@rotateright.com>2018-10-23 14:07:39 +0000
commit5141435d232be4ff1efb841667c931c89525c89f (patch)
tree1e21d8f3c88c964d24d06f0358c884a79014f893
parent6d57266a8cf82b37d79dafebbd5aa81cd0897a64 (diff)
downloadbcm5719-llvm-5141435d232be4ff1efb841667c931c89525c89f.tar.gz
bcm5719-llvm-5141435d232be4ff1efb841667c931c89525c89f.zip
[SLSR] use 'match' to simplify code; NFC
This pass could probably be modified slightly to allow vector splat transforms for practically no cost, but it only works on scalars for now. So the use of the newer 'match' API should make no functional difference. llvm-svn: 345030
-rw-r--r--llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp9
-rw-r--r--llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll29
2 files changed, 34 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
index 2061db13639..b5089b006bd 100644
--- a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
@@ -640,12 +640,12 @@ void StraightLineStrengthReduce::rewriteCandidateWithBasis(
Value *Reduced = nullptr; // equivalent to but weaker than C.Ins
switch (C.CandidateKind) {
case Candidate::Add:
- case Candidate::Mul:
+ case Candidate::Mul: {
// C = Basis + Bump
- if (BinaryOperator::isNeg(Bump)) {
+ Value *NegBump;
+ if (match(Bump, m_Neg(m_Value(NegBump)))) {
// If Bump is a neg instruction, emit C = Basis - (-Bump).
- Reduced =
- Builder.CreateSub(Basis.Ins, BinaryOperator::getNegArgument(Bump));
+ Reduced = Builder.CreateSub(Basis.Ins, NegBump);
// We only use the negative argument of Bump, and Bump itself may be
// trivially dead.
RecursivelyDeleteTriviallyDeadInstructions(Bump);
@@ -662,6 +662,7 @@ void StraightLineStrengthReduce::rewriteCandidateWithBasis(
Reduced = Builder.CreateAdd(Basis.Ins, Bump);
}
break;
+ }
case Candidate::GEP:
{
Type *IntPtrTy = DL->getIntPtrType(C.Ins->getType());
diff --git a/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll b/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll
index c3bffb270af..92af617dab8 100644
--- a/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll
+++ b/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll
@@ -99,6 +99,34 @@ define void @stride_is_minus_2s(i32 %b, i32 %s) {
ret void
}
+; TODO: This pass is targeted at simple address-calcs, so it is artificially limited to
+; match scalar values. The code could be modified to handle vector types too.
+
+define void @stride_is_minus_2s_vec(<2 x i32> %b, <2 x i32> %s) {
+; CHECK-LABEL: @stride_is_minus_2s_vec(
+; CHECK-NEXT: [[S6:%.*]] = mul <2 x i32> [[S:%.*]], <i32 6, i32 6>
+; CHECK-NEXT: [[T1:%.*]] = add <2 x i32> [[B:%.*]], [[S6]]
+; CHECK-NEXT: call void @voo(<2 x i32> [[T1]])
+; CHECK-NEXT: [[S4:%.*]] = shl <2 x i32> [[S]], <i32 2, i32 2>
+; CHECK-NEXT: [[T2:%.*]] = add <2 x i32> [[B]], [[S4]]
+; CHECK-NEXT: call void @voo(<2 x i32> [[T2]])
+; CHECK-NEXT: [[S2:%.*]] = shl <2 x i32> [[S]], <i32 1, i32 1>
+; CHECK-NEXT: [[T3:%.*]] = add <2 x i32> [[B]], [[S2]]
+; CHECK-NEXT: call void @voo(<2 x i32> [[T3]])
+; CHECK-NEXT: ret void
+;
+ %s6 = mul <2 x i32> %s, <i32 6, i32 6>
+ %t1 = add <2 x i32> %b, %s6
+ call void @voo(<2 x i32> %t1)
+ %s4 = shl <2 x i32> %s, <i32 2, i32 2>
+ %t2 = add <2 x i32> %b, %s4
+ call void @voo(<2 x i32> %t2)
+ %s2 = shl <2 x i32> %s, <i32 1, i32 1>
+ %t3 = add <2 x i32> %b, %s2
+ call void @voo(<2 x i32> %t3)
+ ret void
+}
+
; t = b + (s << 3);
; foo(t);
; foo(b + s);
@@ -140,4 +168,5 @@ define void @slsr_strided_add_128bit(i128 %b, i128 %s) {
}
declare void @foo(i32)
+declare void @voo(<2 x i32>)
declare void @bar(i128)
OpenPOWER on IntegriCloud