[llvm-bugs] [Bug 36524] New: [LV] Lost vectorization opportunity

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Feb 26 12:04:20 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36524

            Bug ID: 36524
           Summary: [LV] Lost vectorization opportunity
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: dneilson at azul.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 19965
  --> https://bugs.llvm.org/attachment.cgi?id=19965&action=edit
Sample IR

IR attached:
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: uwtable
define void @foo() #0 {
entry:
  br label %loop

loop:
  %0 = phi i64 [ 2, %entry ], [ %3, %loop ]
  %1 = and i64 %0, 4294967295
  %2 = trunc i64 %0 to i32
  %3 = add nuw nsw i64 %1, 1
  %4 = icmp sgt i32 %2, 80
  br i1 %4, label %exit, label %loop

exit:
  ret void
}

attributes #0 = { uwtable "target-cpu"="bdver1"
"target-features"="+sse2,+cx16,-tbm,-avx512ifma,-gfni,-sha,+fma4,-vpclmulqdq,+prfchw,-bmi2,-xsavec,-fsgsbase,+popcnt,+aes,-avx512bitalg,-xsaves,-avx512er,-avx512vnni,-avx512vpopcntdq,-clwb,-avx512f,-clzero,-pku,+mmx,+lwp,-rdpid,+xop,-rdseed,-ibt,+sse4a,-avx512bw,-clflushopt,+xsave,-avx512vbmi2,-avx512vl,-avx512cd,+avx,-vaes,-rtm,-fma,-bmi,-rdrnd,-mwaitx,+sse4.1,+sse4.2,-avx2,+sse,+lzcnt,+pclmul,-prefetchwt1,-f16c,+ssse3,-sgx,-shstk,+cmov,-avx512vbmi,-movbe,-xsaveopt,-avx512dq,-adx,-avx512pf,+sse3"
}

----

When run through the loop vectorizer with ToT we do not vectorize this loop.
However, it did once vectorize in the fairly recent past. There's a bit of a
history on this one...

https://reviews.llvm.org/rL320463 -- is the last LoopVectorizer.cpp change that
vectorizes this loop.

https://reviews.llvm.org/rL320672 -- breaks the test, with an assertion in
VPlan:
r320672 | dorit.nuzman | 2017-12-14 01:56:31 -0600 (Thu, 14 Dec 2017) | 26
lines

[LV] Support efficient vectorization of an induction with redundant casts
==
Assertion failed: (!hasVectorValue(Key, Part) && "Vector value already set for
part"), function setVectorValue, file lib/Transforms/Vectorize/VPlan.h, line
166.
0  opt                      0x000000010b8e44bc
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  opt                      0x000000010b8e4ab9
PrintStackTraceSignalHandler(void*) + 25
2  opt                      0x000000010b8e0549 llvm::sys::RunSignalHandlers() +
425
3  opt                      0x000000010b8e4e72 SignalHandler(int) + 354
4  libsystem_platform.dylib 0x00007fff64326f5a _sigtramp + 26
5  libdyld.dylib            0x00007fff640a5249 dyldGlobalLockRelease() + 0
6  libsystem_c.dylib        0x00007fff64151312 abort + 127
7  libsystem_c.dylib        0x00007fff64119368 basename_r + 0
8  opt                      0x000000010ba87eb0
llvm::VectorizerValueMap::setVectorValue(llvm::Value*, unsigned int,
llvm::Value*) + 160
9  opt                      0x000000010ba88100
llvm::InnerLoopVectorizer::recordVectorLoopValueForInductionCast(llvm::InductionDescriptor
const&, llvm::Value*, unsigned int, unsigned int) + 208
10 opt                      0x000000010ba89375
llvm::InnerLoopVectorizer::widenIntOrFpInduction(llvm::PHINode*,
llvm::TruncInst*) + 2533
11 opt                      0x000000010bac0ed0 (anonymous
namespace)::VPWidenIntOrFpInductionRecipe::execute(llvm::VPTransformState&) +
144
12 opt                      0x000000010bb64bfa
llvm::VPBasicBlock::execute(llvm::VPTransformState*) + 842
13 opt                      0x000000010bb66037
llvm::VPlan::execute(llvm::VPTransformState*) + 855
14 opt                      0x000000010ba9a22e
llvm::LoopVectorizationPlanner::executePlan(llvm::InnerLoopVectorizer&,
llvm::DominatorTree*) + 430
15 opt                      0x000000010baa2ad2
llvm::LoopVectorizePass::processLoop(llvm::Loop*) + 8482

https://reviews.llvm.org/rL322473 -- Changes the breakage. It's still broken,
but the assert has changed
r322473 | andrei.elovikov | 2018-01-15 04:56:07 -0600 (Mon, 15 Jan 2018) | 24
lines

[LV] Don't call recordVectorLoopValueForInductionCast for newly-created IV from
a trunc.
==
Assertion failed: (!hasScalarValue(Key, Instance) && "Scalar value already
set"), function setScalarValue, file lib/Transforms/Vectorize/VPlan.h, line
173.
0  opt                      0x000000010429f82c
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  opt                      0x000000010429fe29
PrintStackTraceSignalHandler(void*) + 25
2  opt                      0x000000010429b8b9 llvm::sys::RunSignalHandlers() +
425
3  opt                      0x00000001042a01e2 SignalHandler(int) + 354
4  libsystem_platform.dylib 0x00007fff64326f5a _sigtramp + 26
5  libdyld.dylib            0x00007fff640a5249 dyldGlobalLockRelease() + 0
6  libsystem_c.dylib        0x00007fff64151312 abort + 127
7  libsystem_c.dylib        0x00007fff64119368 basename_r + 0
8  opt                      0x000000010444662f
llvm::VectorizerValueMap::setScalarValue(llvm::Value*, llvm::VPIteration
const&, llvm::Value*) + 175
9  opt                      0x0000000104446143
llvm::InnerLoopVectorizer::recordVectorLoopValueForInductionCast(llvm::InductionDescriptor
const&, llvm::Value*, unsigned int, unsigned int) + 163
10 opt                      0x0000000104447ba4
llvm::InnerLoopVectorizer::buildScalarSteps(llvm::Value*, llvm::Value*,
llvm::Value*, llvm::InductionDescriptor const&) + 852
11 opt                      0x00000001044474a1
llvm::InnerLoopVectorizer::widenIntOrFpInduction(llvm::PHINode*,
llvm::TruncInst*) + 2721
12 opt                      0x0000000104474390
llvm::VPWidenIntOrFpInductionRecipe::execute(llvm::VPTransformState&) + 144
13 opt                      0x000000010452300a
llvm::VPBasicBlock::execute(llvm::VPTransformState*) + 842
14 opt                      0x0000000104524447
llvm::VPlan::execute(llvm::VPTransformState*) + 855
15 opt                      0x000000010446d9ce
llvm::LoopVectorizationPlanner::executePlan(llvm::InnerLoopVectorizer&,
llvm::DominatorTree*) + 430
16 opt                      0x0000000104477cc2
llvm::LoopVectorizePass::processLoop(llvm::Loop*) + 8482


https://reviews.llvm.org/rL326079 -- The assertion is now gone, but the loop is
no longer vectorized.
r326079 | renato.golin | 2018-02-26 05:06:36 -0600 (Mon, 26 Feb 2018) | 21
lines

[LV] Move isLegalMasked* functions from Legality to CostModel

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180226/7defddc1/attachment.html>


More information about the llvm-bugs mailing list