From 43ce19524ff7fb8cdebdf42450bcd2155f3882b3 Mon Sep 17 00:00:00 2001 From: Ayal Zaks Date: Tue, 15 Aug 2017 08:32:59 +0000 Subject: [PATCH] [LV] Minor savings to Sink casts to unravel first order recurrence Two minor savings: avoid copying the SinkAfter map and avoid moving a cast if it is not needed. Differential Revision: https://reviews.llvm.org/D36408 llvm-svn: 310910 --- lib/Transforms/Utils/LoopUtils.cpp | 3 ++- lib/Transforms/Vectorize/LoopVectorize.cpp | 2 +- test/Transforms/LoopVectorize/first-order-recurrence.ll | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Utils/LoopUtils.cpp b/lib/Transforms/Utils/LoopUtils.cpp index 3c522786641..f2015c6389b 100644 --- a/lib/Transforms/Utils/LoopUtils.cpp +++ b/lib/Transforms/Utils/LoopUtils.cpp @@ -565,7 +565,8 @@ bool RecurrenceDescriptor::isFirstOrderRecurrence( auto *I = Phi->user_back(); if (I->isCast() && (I->getParent() == Phi->getParent()) && I->hasOneUse() && DT->dominates(Previous, I->user_back())) { - SinkAfter[I] = Previous; + if (!DT->dominates(Previous, I)) // Otherwise we're good w/o sinking. + SinkAfter[I] = Previous; return true; } } diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 5c640542e9a..adde81984c2 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7655,7 +7655,7 @@ void LoopVectorizationPlanner::executePlan(InnerLoopVectorizer &ILV) { // 2. Copy and widen instructions from the old loop into the new loop. // Move instructions to handle first-order recurrences. - DenseMap SinkAfter = Legal->getSinkAfter(); + DenseMap &SinkAfter = Legal->getSinkAfter(); for (auto &Entry : SinkAfter) { Entry.first->removeFromParent(); Entry.first->insertAfter(Entry.second); diff --git a/test/Transforms/LoopVectorize/first-order-recurrence.ll b/test/Transforms/LoopVectorize/first-order-recurrence.ll index 508938958d5..3a8237ff84f 100644 --- a/test/Transforms/LoopVectorize/first-order-recurrence.ll +++ b/test/Transforms/LoopVectorize/first-order-recurrence.ll @@ -140,7 +140,10 @@ scalar.body: ; CHECK: vector.body: ; CHECK: %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ] ; CHECK: [[L1]] = load <4 x i16> -; CHECK: {{.*}} = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> +; CHECK: [[SHUF:%[a-zA-Z0-9.]+]] = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> +; Check also that the casts were not moved needlessly. +; CHECK: sitofp <4 x i16> [[L1]] to <4 x double> +; CHECK: sitofp <4 x i16> [[SHUF]] to <4 x double> ; CHECK: middle.block: ; CHECK: %vector.recur.extract = extractelement <4 x i16> [[L1]], i32 3 ; CHECK: scalar.ph: