[PATCH] D22918: [Loop Vectorizer] Support predication of div/rem
Adam Nemet via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 10:10:58 PDT 2016
anemet added a comment.
More drive-by comments.
================
Comment at: lib/Transforms/Vectorize/LoopVectorize.cpp:3835-3844
@@ -3784,7 +3834,12 @@
+
+void InnerLoopVectorizer::predicateInstructions() {
+ for (auto KV : PredicatedInstructions) {
BasicBlock::iterator I(KV.first);
- auto *BB = SplitBlock(I->getParent(), &*std::next(I), DT, LI);
+ BasicBlock *Head = I->getParent();
+ auto *BB = SplitBlock(Head, &*std::next(I), DT, LI);
auto *T = SplitBlockAndInsertIfThen(KV.second, &*I, /*Unreachable=*/false,
/*BranchWeights=*/nullptr, DT, LI);
I->moveBefore(T);
- I->getParent()->setName("pred.store.if");
- BB->setName("pred.store.continue");
+ // Try to move any extract-element we may have created for the predicated
+ // instruction into the Then block.
+ for (Use &Op : I->operands()) {
----------------
Would be good to describe the high-level strategy of how we predicate these instruction, perhaps with an IR example.
================
Comment at: lib/Transforms/Vectorize/LoopVectorize.cpp:3860-3861
@@ +3859,4 @@
+
+ I->getParent()->setName(Twine("pred.") + Twine(I->getOpcodeName()) +
+ Twine(".if"));
+ BB->setName(Twine("pred.") + Twine(I->getOpcodeName()) +
----------------
I think that Twine knows how to concatenate string-like things. You only need the explicit ctor on the first one.
================
Comment at: test/Transforms/LoopVectorize/if-pred-non-void.ll:18-51
@@ +17,36 @@
+
+; CHECK-LABEL: test
+; CHECK: vector.body:
+; CHECK: %{{.*}} = extractelement <2 x i1> %{{.*}}, i32 0
+; CHECK: br i1 %{{.*}}, label %[[csd:[a-zA-Z0-9.]+]], label %[[esd:[a-zA-Z0-9.]+]]
+; CHECK: [[csd]]:
+; CHECK: %[[sd0:[a-zA-Z0-9]+]] = sdiv i32 %{{.*}}, %{{.*}}
+; CHECK: %[[sd1:[a-zA-Z0-9]+]] = insertelement <2 x i32> undef, i32 %[[sd0]], i32 0
+; CHECK: br label %[[esd]]
+; CHECK: [[esd]]:
+; CHECK: %{{.*}} = phi <2 x i32> [ undef, %vector.body ], [ %[[sd1]], %[[csd]] ]
+; CHECK: %{{.*}} = extractelement <2 x i1> %{{.*}}, i32 0
+; CHECK: br i1 %{{.*}}, label %[[cud:[a-zA-Z0-9.]+]], label %[[eud:[a-zA-Z0-9.]+]]
+; CHECK: [[cud]]:
+; CHECK: %[[ud0:[a-zA-Z0-9]+]] = udiv i32 %{{.*}}, %{{.*}}
+; CHECK: %[[ud1:[a-zA-Z0-9]+]] = insertelement <2 x i32> undef, i32 %[[ud0]], i32 0
+; CHECK: br label %[[eud]]
+; CHECK: [[eud]]:
+; CHECK: %{{.*}} = phi <2 x i32> [ undef, %{{.*}} ], [ %[[ud1]], %[[cud]] ]
+; CHECK: %{{.*}} = extractelement <2 x i1> %{{.*}}, i32 0
+; CHECK: br i1 %{{.*}}, label %[[csr:[a-zA-Z0-9.]+]], label %[[esr:[a-zA-Z0-9.]+]]
+; CHECK: [[csr]]:
+; CHECK: %[[sr0:[a-zA-Z0-9]+]] = srem i32 %{{.*}}, %{{.*}}
+; CHECK: %[[sr1:[a-zA-Z0-9]+]] = insertelement <2 x i32> undef, i32 %[[sr0]], i32 0
+; CHECK: br label %[[esr]]
+; CHECK: [[esr]]:
+; CHECK: %{{.*}} = phi <2 x i32> [ undef, %{{.*}} ], [ %[[sr1]], %[[csr]] ]
+; CHECK: %{{.*}} = extractelement <2 x i1> %{{.*}}, i32 0
+; CHECK: br i1 %{{.*}}, label %[[cur:[a-zA-Z0-9.]+]], label %[[eur:[a-zA-Z0-9.]+]]
+; CHECK: [[cur]]:
+; CHECK: %[[ur0:[a-zA-Z0-9]+]] = urem i32 %{{.*}}, %{{.*}}
+; CHECK: %[[ur1:[a-zA-Z0-9]+]] = insertelement <2 x i32> undef, i32 %[[ur0]], i32 0
+; CHECK: br label %[[eur]]
+; CHECK: [[eur]]:
+; CHECK: %{{.*}} = phi <2 x i32> [ undef, %{{.*}} ], [ %[[ur1]], %[[cur]] ]
+
----------------
I *think* we're pretty consistent about using uppercase for the named regexes. That helps readability.
https://reviews.llvm.org/D22918
More information about the llvm-commits
mailing list