This is an archive of the discontinued LLVM Phabricator instance.

Recommit "[SLP] Fix lookahead operand reordering for splat loads."
ClosedPublic

Authored by vporpo on Mar 17 2022, 7:33 PM.

Diff Detail

Event Timeline

vporpo created this revision.Mar 17 2022, 7:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 7:33 PM
vporpo requested review of this revision.Mar 17 2022, 7:33 PM

@ABataev could you rubber stamp this once more? The only difference from https://reviews.llvm.org/D121354 is the missing Args argument in getShuffleCost for the various targets.

This revision is now accepted and ready to land.Mar 21 2022, 3:32 PM
This revision was landed with ongoing or failed builds.Mar 21 2022, 3:58 PM
This revision was automatically updated to reflect the committed changes.

this causes crashes:

$ cat /tmp/a.ll
target triple = "x86_64-unknown-linux-gnu"

define internal fastcc void @0() #0 {
  %1 = load double, double* null, align 8
  %2 = fcmp ogt double 0.000000e+00, %1
  %3 = fcmp ogt double 0.000000e+00, %1
  ret void
}

attributes #0 = { "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+sse3,+x87" }

$ bin/opt -passes=slp-vectorizer -disable-output /tmp/a.ll
opt: ../../llvm/lib/Target/X86/X86TargetTransformInfo.cpp:1563: llvm::InstructionCost llvm::X86TTIImpl::getShuffleCost(TTI::ShuffleKind, llvm::VectorType *, ArrayRef<int>, int, llvm::VectorType *, ArrayRef<llvm::Value *>): Assertion `isLegalBroadcastLoad( BaseTp->getElementType(), cast<FixedVectorType>(BaseTp)->getNumElements()) && "Table entry missing from isLegalBroadcastLoad()"' failed.

Thanks @aeubanks for reporting this and for providing a reproducer.
The cause of the crash was a typo hasSSSE3() instead of hasSSE3() which was causing the assertion in X86TargetTransformInfo.cpp:1561 assert(isLegalBroadcast(...) to crash. I recommitted the patch: 27bd8f94928201f87f6b659fc2228efd539e8245

One more crash:

$ cat /tmp/a.ll
target triple = "x86_64-pc-windows-msvc19.16.0"

%class.MockPrinter = type { %"class.gfx::Size", %"class.gfx::Size" }
%"class.gfx::Size" = type { i32, i32 }

define %class.MockPrinter* @"??0MockPrinter@@QEAA@XZ"(%class.MockPrinter* %this) #0 {
entry:
  %page_size_ = getelementptr inbounds %class.MockPrinter, %class.MockPrinter* %this, i64 0, i32 0
  %content_size_ = getelementptr inbounds %class.MockPrinter, %class.MockPrinter* %this, i64 0, i32 1
  %0 = load double, double* null, align 8
  %mul = fmul double %0, 0.000000e+00
  %conv = fptosi double %mul to i32
  %mul10 = fmul double %0, 0.000000e+00
  %conv11 = fptosi double %mul10 to i32
  %width_.i.i = getelementptr inbounds %"class.gfx::Size", %"class.gfx::Size"* %page_size_, i64 0, i32 0
  store i32 %conv11, i32* %width_.i.i, align 4
  %height_.i.i = getelementptr inbounds %"class.gfx::Size", %"class.gfx::Size"* %page_size_, i64 0, i32 1
  store i32 %conv, i32* %height_.i.i, align 4
  %mul14 = fmul double %0, 0.000000e+00
  %conv15 = fptosi double %mul14 to i32
  %mul17 = fmul double %0, 0.000000e+00
  %conv18 = fptosi double %mul17 to i32
  %width_.i.i3 = getelementptr inbounds %"class.gfx::Size", %"class.gfx::Size"* %content_size_, i64 0, i32 0
  store i32 %conv18, i32* %width_.i.i3, align 4
  %height_.i.i4 = getelementptr inbounds %"class.gfx::Size", %"class.gfx::Size"* %content_size_, i64 0, i32 1
  store i32 %conv15, i32* %height_.i.i4, align 4
  ret %class.MockPrinter* null
}

attributes #0 = { "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+sse3,+x87" }
$ bin/opt -passes='slp-vectorizer' -disable-output /tmp/a.ll
opt: ../../llvm/lib/Target/X86/X86TargetTransformInfo.cpp:1563: llvm::InstructionCost llvm::X86TTIImpl::getShuffleCost(TTI::ShuffleKind, llvm::VectorType *, ArrayRef<int>, int, llvm::VectorType *, ArrayRef<llvm::Value *>): Assertion `isLegalBroadcastLoad( BaseTp->getElementType(), cast<FixedVectorType>(BaseTp)->getNumElements()) && "Table entry missing from isLegalBroadcastLoad()"' failed.                                                                                                                                                                                                 
RKSimon added inline comments.Mar 23 2022, 11:43 AM
llvm/lib/Target/X86/X86TargetTransformInfo.cpp
1562

This isn't accounting for type legalization reducing the width of the broadcasted vector - you probably need to use LT.second.getVectorNumElements().

llvm/lib/Target/X86/X86TargetTransformInfo.cpp
1562

Yeah this was the issue, thanks!