[PATCH] D12289: [LV] When emitting an overflow check, test the trip count, not the backedge count.
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 09:13:36 PDT 2015
jmolloy created this revision.
jmolloy added reviewers: anemet, mzolotukhin.
jmolloy added a subscriber: llvm-commits.
jmolloy set the repository for this revision to rL LLVM.
We were testing the backedge-taken count with -1, when it's just as simple to test the trip count with zero. Given we need to calculate the trip count anyway, this removes code in the loop vectorizer.
Repository:
rL LLVM
http://reviews.llvm.org/D12289
Files:
lib/Transforms/Vectorize/LoopVectorize.cpp
test/Transforms/LoopVectorize/induction.ll
Index: test/Transforms/LoopVectorize/induction.ll
===================================================================
--- test/Transforms/LoopVectorize/induction.ll
+++ test/Transforms/LoopVectorize/induction.ll
@@ -112,8 +112,8 @@
; condition and branch directly to the scalar loop.
; CHECK-LABEL: max_i32_backedgetaken
-; CHECK: %backedge.overflow = icmp eq i32 -1, -1
-; CHECK: br i1 %backedge.overflow, label %scalar.ph, label %overflow.checked
+; CHECK: tc.overflow = icmp eq i32 0, 0
+; CHECK: br i1 %tc.overflow, label %scalar.ph, label %overflow.checked
; CHECK: scalar.ph:
; CHECK: %bc.resume.val = phi i32 [ %resume.val, %middle.block ], [ 0, %0 ]
Index: lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- lib/Transforms/Vectorize/LoopVectorize.cpp
+++ lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2650,29 +2650,22 @@
// Notice that the pre-header does not change, only the loop body.
SCEVExpander Exp(*SE, DL, "induction");
+ // Count holds the overall loop count (N).
+ Value *Count = Exp.expandCodeFor(ExitCount, ExitCount->getType(),
+ VectorPH->getTerminator());
+
// We need to test whether the backedge-taken count is uint##_max. Adding one
// to it will cause overflow and an incorrect loop trip count in the vector
// body. In case of overflow we want to directly jump to the scalar remainder
// loop.
- Value *BackedgeCount =
- Exp.expandCodeFor(BackedgeTakeCount, BackedgeTakeCount->getType(),
- VectorPH->getTerminator());
- if (BackedgeCount->getType()->isPointerTy())
- BackedgeCount = CastInst::CreatePointerCast(BackedgeCount, IdxTy,
- "backedge.ptrcnt.to.int",
- VectorPH->getTerminator());
Instruction *CheckBCOverflow =
- CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, BackedgeCount,
- Constant::getAllOnesValue(BackedgeCount->getType()),
- "backedge.overflow", VectorPH->getTerminator());
+ CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, Count,
+ Constant::getNullValue(Count->getType()),
+ "tc.overflow", VectorPH->getTerminator());
Builder.SetInsertPoint(VectorPH->getTerminator());
Value *StartIdx = ExtendedIdx = ConstantInt::get(IdxTy, 0);
- // Count holds the overall loop count (N).
- Value *Count = Exp.expandCodeFor(ExitCount, ExitCount->getType(),
- VectorPH->getTerminator());
-
LoopBypassBlocks.push_back(VectorPH);
// Split the single block loop into the two loop structure described above.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12289.32968.patch
Type: text/x-patch
Size: 2759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150824/966a52ec/attachment.bin>
More information about the llvm-commits
mailing list