This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Unify Value2VPValue and VPExternalDefs maps (NFCI).
ClosedPublic

Authored by fhahn on Apr 9 2023, 12:56 PM.

Details

Summary

Before this patch, a VPlan contained 2 mappings for Values -> VPValue:

  1. Value2VPValue and 2) VPExternalDefs.

This duplication is unnecessary and there are already cases where
external defs are added to Value2VPValue. This patch replaces all uses
of VPExternalDefs with Value2VPValue.

It clarifies the naming of getOrAddVPValue (to getOrAddExternalVPValue)
and addVPValue (to addExternalVPValue).

At the moment, this is NFC, but will enable additional simplifications
in D147783.

Depends on D147891.

Diff Detail

Event Timeline

fhahn created this revision.Apr 9 2023, 12:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2023, 12:56 PM
fhahn requested review of this revision.Apr 9 2023, 12:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2023, 12:56 PM
Ayal added a comment.Apr 13 2023, 10:06 AM

This indeed deserves cleaning up!
Would it be correct and reasonable to rename "External[Def]" >> "LiveIn[VPValue]" throughout, as in !hasDefiningRecipe()?
Value2VPValueEnabled presumably applies to recipe'd VPValues only, i.e., excluding live-in VPValues? Better decrease allowed overriding cases, rather than increase them.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
8150

nit (Independent of this patch): assert seems redundant - getOrAdd*() cannot return null?

8879

nit (Independent of this patch): should this case add a

// FIXME: Should not rely on getVPValue at this point.

referring to D108573?

10481

Explain why override is allowed? Add above FIXME?

llvm/lib/Transforms/Vectorize/VPlan.h
2252

Still only to remember whom to destroy? Worth retaining ToFree suffix?

2256

For live-ins/external-defs, the mapping is always intact?

Perhaps distinguish between getting a VPValue which may be a recipe, for which the mapping will become stale, and getting-or-adding a live-in VPValue?

2333

Note that addVPValue(Value*, VPValue*) remains intact, it is only addVPValue(Value*) which is renamed addExternalVPValue(Value*) below, as the former adds recipe VPValues whereas the latter adds live-in ones.

2343

Note that getVPValue() remains intact, used to retrieve both live-ins and recipe VPValues, although if used to retrieve live-ins it should disregard Value2VPValueEnabled - the obvious case being constants checked below.

2353

This adds a live-in, so indeed should be enabled always, regardless of Value2VPValueEnabled; although currently addVPValue(Value*) which adds a live-in does check Value2VPValueEnabled.

2364

getOrAddExternalVPValue() deals with live-in VPValues only, why should it consider Value2VPValueEnabled?

2365

Indeed, VPV must not have a defining recipe when expecting to get a live-in/external VPValue.

fhahn updated this revision to Diff 513915.Apr 15 2023, 8:36 AM
fhahn marked an inline comment as done.

This indeed deserves cleaning up!
Would it be correct and reasonable to rename "External[Def]" >> "LiveIn[VPValue]" throughout, as in !hasDefiningRecipe()?

Update, thanks!

Value2VPValueEnabled presumably applies to recipe'd VPValues only, i.e., excluding live-in VPValues? Better decrease allowed overriding cases, rather than increase them.

I updated the exsting asserts to allow querying and adding live-ins regardless of Value2VPValueEnabled and consolidated the functions.

fhahn marked 9 inline comments as done.Apr 15 2023, 8:40 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
8150

Yeah, I can remove it separately.

8879

Update the code, the new getVPValueOrAddLiveIn only doesn't require the parameter, as live-ins can be added regardless.

10481

Update getOrAddLiveIn to be allowed generally.

llvm/lib/Transforms/Vectorize/VPlan.h
2252

Retained, thanks!

2256

Agreed, updated to always allow querying and adding live-ins.

2333

addExternalVPValue has been removed and addVPValue(Value*, VPValue*) has been updated to also handle the live-in case in the assert

2343

Updated to allow retrieving live-ins in the assert.

2353

This is gone now.

2364

Removed assert and renamed getVPValueOrAddLiveIn and updated the code to use existing addVPValue and getVPValue

Ayal accepted this revision.Apr 15 2023, 1:43 PM

Looks good to me, thanks!

llvm/lib/Transforms/Vectorize/VPlan.h
2334–2335

nit: an isLiveIn() method may be clearer than these !getDefiningRecipe()'s.

2342

Retain documentation of \p OverrideAllowed?

This revision is now accepted and ready to land.Apr 15 2023, 1:43 PM
This revision was landed with ongoing or failed builds.Apr 16 2023, 7:38 AM
This revision was automatically updated to reflect the committed changes.
fhahn marked 8 inline comments as done.

(Repost from github)

This patch appears to cause a heap-use-after-free e.g., https://lab.llvm.org/buildbot/#/builders/239/builds/1843/steps/14/logs/stdio:

FAIL: LLVM :: Transforms/LoopVectorize/SystemZ/pr38110.ll (57359 of 71288)
******************** TEST 'LLVM :: Transforms/LoopVectorize/SystemZ/pr38110.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/opt -passes='loop-vectorize' -mcpu=z13 -force-vector-width=2 -S < /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/Transforms/LoopVectorize/SystemZ/pr38110.ll | /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/Transforms/LoopVectorize/SystemZ/pr38110.ll
--
Exit Code: 2
Command Output (stderr):
--
=================================================================
==932340==ERROR: AddressSanitizer: heap-use-after-free on address 0x50e000000b50 at pc 0xaaaacf039884 bp 0xffffca0e3220 sp 0xffffca0e3218
READ of size 8 at 0x50e000000b50 thread T0
    #0 0xaaaacf039880 in llvm::VPValue::getDefiningRecipe() /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.cpp:117:37
    #1 0xaaaacef5cda4 in llvm::VPlan::getVPValue(llvm::Value*, bool) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.h:2346:5
    #2 0xaaaacef5a7c4 in llvm::InnerLoopVectorizer::truncateToMinimalBitwidths(llvm::VPTransformState&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:3611:32
    #3 0xaaaacef5d648 in llvm::InnerLoopVectorizer::fixVectorizedLoop(llvm::VPTransformState&, llvm::VPlan&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:3739:5
    #4 0xaaaacefaf0e4 in llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7802:7
    #5 0xaaaacefe67c8 in llvm::LoopVectorizePass::processLoop(llvm::Loop*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10496:13
    #6 0xaaaaceff4028 in llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10593:30
    #7 0xaaaaceff5440 in llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10626:9
    #8 0xaaaacd88aaa8 in llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/IR/PassManager.h:517:40
    #9 0xaaaacd896838 in llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/IR/PassManager.cpp:124:38
    #10 0xaaaacd888284 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/IR/PassManager.h:517:40
    #11 0xaaaac851509c in llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/tools/opt/NewPMDriver.cpp:522:7
    #12 0xaaaac85446c4 in main /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/tools/opt/opt.cpp:701:12
    #13 0xffff92e373f8  (/lib/aarch64-linux-gnu/libc.so.6+0x273f8) (BuildId: f37f3aa07c797e333fd106472898d361f71798f5)
    #14 0xffff92e374c8 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x274c8) (BuildId: f37f3aa07c797e333fd106472898d361f71798f5)
    #15 0xaaaac842bb6c in _start (/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/opt+0x7f6bb6c)
vitalybuka reopened this revision.Apr 17 2023, 5:24 PM
This revision is now accepted and ready to land.Apr 17 2023, 5:24 PM
fhahn added a comment.Apr 18 2023, 2:31 AM

(Repost from github)

This patch appears to cause a heap-use-after-free e.g., https://lab.llvm.org/buildbot/#/builders/239/builds/1843/steps/14/logs/stdio:

FAIL: LLVM :: Transforms/LoopVectorize/SystemZ/pr38110.ll (57359 of 71288)
******************** TEST 'LLVM :: Transforms/LoopVectorize/SystemZ/pr38110.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/opt -passes='loop-vectorize' -mcpu=z13 -force-vector-width=2 -S < /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/Transforms/LoopVectorize/SystemZ/pr38110.ll | /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/Transforms/LoopVectorize/SystemZ/pr38110.ll
--
Exit Code: 2
Command Output (stderr):
--
=================================================================
==932340==ERROR: AddressSanitizer: heap-use-after-free on address 0x50e000000b50 at pc 0xaaaacf039884 bp 0xffffca0e3220 sp 0xffffca0e3218
READ of size 8 at 0x50e000000b50 thread T0
    #0 0xaaaacf039880 in llvm::VPValue::getDefiningRecipe() /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.cpp:117:37
    #1 0xaaaacef5cda4 in llvm::VPlan::getVPValue(llvm::Value*, bool) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.h:2346:5
    #2 0xaaaacef5a7c4 in llvm::InnerLoopVectorizer::truncateToMinimalBitwidths(llvm::VPTransformState&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:3611:32
    #3 0xaaaacef5d648 in llvm::InnerLoopVectorizer::fixVectorizedLoop(llvm::VPTransformState&, llvm::VPlan&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:3739:5
    #4 0xaaaacefaf0e4 in llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7802:7
    #5 0xaaaacefe67c8 in llvm::LoopVectorizePass::processLoop(llvm::Loop*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10496:13
    #6 0xaaaaceff4028 in llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10593:30
    #7 0xaaaaceff5440 in llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10626:9
    #8 0xaaaacd88aaa8 in llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/IR/PassManager.h:517:40
    #9 0xaaaacd896838 in llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/lib/IR/PassManager.cpp:124:38
    #10 0xaaaacd888284 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/IR/PassManager.h:517:40
    #11 0xaaaac851509c in llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/tools/opt/NewPMDriver.cpp:522:7
    #12 0xaaaac85446c4 in main /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/tools/opt/opt.cpp:701:12
    #13 0xffff92e373f8  (/lib/aarch64-linux-gnu/libc.so.6+0x273f8) (BuildId: f37f3aa07c797e333fd106472898d361f71798f5)
    #14 0xffff92e374c8 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x274c8) (BuildId: f37f3aa07c797e333fd106472898d361f71798f5)
    #15 0xaaaac842bb6c in _start (/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/opt+0x7f6bb6c)

Thanks for the revert, should be fixed by adjusting the order of the conditions in the assert in VPValue in the recommitted version.

fhahn closed this revision.Apr 18 2023, 2:31 AM

Recommitted as ff0ec4f42ea0

fhahn marked an inline comment as done.Apr 24 2023, 9:51 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/VPlan.h
2334–2335

Thank you Florian! :-)