This is an archive of the discontinued LLVM Phabricator instance.

[SwiftError] Use IMPLICIT_DEF as a definition for unreachable VReg uses
ClosedPublic

Authored by fzhinkin on Jan 5 2023, 6:58 AM.

Details

Summary

SwiftErrorValueTracking creates vregs at swifterror use sites and then
connects it with appropriate definitions after instruction selection.
To propagate swifterror values SwiftErrorValueTracking::propagateVRegs
iterates over basic blocks in RPO, but some vregs previously created
at use sites may be located in blocks that became unreachable after
instruction selection. Because of that there will no definition for
such vregs and that may cause issues down the pipeline.

To ensure that all vregs created by the SwiftErrorValueTracking will
be defined propagateVRegs was updated to insert IMPLICIT_DEF at the
beginning of unreachable blocks containing swifterror uses.

Related issue: https://github.com/llvm/llvm-project/issues/59751

Diff Detail

Event Timeline

fzhinkin created this revision.Jan 5 2023, 6:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 6:58 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fzhinkin published this revision for review.Jan 5 2023, 7:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 7:05 AM
compnerd added inline comments.Jan 5 2023, 10:05 AM
llvm/lib/CodeGen/SwiftErrorValueTracking.cpp
259–261

I think that we can simplify this to:

for (const auto *Use : VRegUpwardsUse) {
  const MachineBasicBlock *UseBB = Use.first.first;
  Register VReg = Use.second;
266

Should this be an expensive assert?

llvm/test/CodeGen/AArch64/swift-error-unreachable-use.ll
2

Please expand this into three explicit invocations:

llc -mtriple aarch64-unknown-windows-msvc %s -filetype asm -o - | FileCheck %s
llc -mtriple aarch64-unknown-linux-gnu %s -filetype asm -o - | FileCheck %s
llc -mtriple aarch64-apple-macosx10.15 %s -filetype asm -o - | FileCheck %s

The test should actually validate that the output is correct.

fzhinkin updated this revision to Diff 486752.Jan 5 2023, 11:03 PM

Cleaned up the code, updated test.

fzhinkin added inline comments.Jan 8 2023, 11:50 PM
llvm/lib/CodeGen/SwiftErrorValueTracking.cpp
266

Thanks for suggestion, fixed.

llvm/test/CodeGen/AArch64/swift-error-unreachable-use.ll
2

Updated the test, thanks for suggestion!

compnerd added inline comments.Feb 28 2023, 10:30 AM
llvm/test/CodeGen/AArch64/swift-error-unreachable-use.ll
28

Why not use a regex group to handle the comment leader? These are identical.

fzhinkin updated this revision to Diff 505032.Mar 14 2023, 4:39 AM

Cleaned up the test

llvm/test/CodeGen/AArch64/swift-error-unreachable-use.ll
28

Thank you for suggestion, I updated the test.

compnerd accepted this revision.Aug 17 2023, 7:18 AM
This revision is now accepted and ready to land.Aug 17 2023, 7:18 AM