This is an archive of the discontinued LLVM Phabricator instance.

[SLP]Fix reused extracts cost.
ClosedPublic

Authored by ABataev on Dec 2 2021, 6:51 AM.

Details

Summary

If the extractelement instruction is used multiple times in the
different tree entries (either vectorized, or gathered), need to
compensate the scalar cost of such instructions. They are completely
removed if all users are part of the tree but we need to compensate the
cost only once for each instruction.

Diff Detail

Event Timeline

ABataev created this revision.Dec 2 2021, 6:51 AM
ABataev requested review of this revision.Dec 2 2021, 6:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2021, 6:51 AM
RKSimon accepted this revision.Dec 2 2021, 10:18 AM

LGTM

This revision is now accepted and ready to land.Dec 2 2021, 10:18 AM
This revision was automatically updated to reflect the committed changes.
qiongsiwu1 added subscribers: RolandF, qiongsiwu1.EditedDec 7 2021, 7:28 AM

This patch causes a crash when compiling the IR below.

define dso_local void @foo() local_unnamed_addr {
entry:
  %0 = extractelement <2 x double> undef, i32 1
  br label %loop_do_

loop_do_:
  %a1 = phi double [ %a1, %loop_do_ ], [ %0, %entry ]
  %a2 = phi double [ undef, %loop_do_ ], [ undef, %entry ]
  br label %loop_do_
}

The patch moved the isSlat(VL) check after it processes ExtractValue, but this test case has a tree where one value is undef, and the other is an extractvalue. Should we match not only isa<ExtractElementInst, UndefValue>(V), but also an undef value itself as well?

Thanks a lot! FYI @RolandF

This patch causes a crash when compiling the IR below.

define dso_local void @foo() local_unnamed_addr {
entry:
  %0 = extractelement <2 x double> undef, i32 1
  br label %loop_do_

loop_do_:
  %a1 = phi double [ %a1, %loop_do_ ], [ %0, %entry ]
  %a2 = phi double [ undef, %loop_do_ ], [ undef, %entry ]
  br label %loop_do_
}

The patch moved the isSlat(VL) check after we process ExtractValue, but this test case has a tree where one value is undef, and the other is an extractvalue. Should we match not only isa<ExtractElementInst, UndefValue>(V), but also an undef value itself as well?

Thanks a lot! FYI @RolandF

Hi, committed a101a9b64b31ed20e4d18c2e395b0a3742ad1836 yesterday to fix it, could you try to update your compiler?

This patch causes a crash when compiling the IR below.

define dso_local void @foo() local_unnamed_addr {
entry:
  %0 = extractelement <2 x double> undef, i32 1
  br label %loop_do_

loop_do_:
  %a1 = phi double [ %a1, %loop_do_ ], [ %0, %entry ]
  %a2 = phi double [ undef, %loop_do_ ], [ undef, %entry ]
  br label %loop_do_
}

The patch moved the isSlat(VL) check after we process ExtractValue, but this test case has a tree where one value is undef, and the other is an extractvalue. Should we match not only isa<ExtractElementInst, UndefValue>(V), but also an undef value itself as well?

Thanks a lot! FYI @RolandF

Hi, committed a101a9b64b31ed20e4d18c2e395b0a3742ad1836 yesterday to fix it, could you try to update your compiler?

Ah great! Thanks!