This patch introduces a new AA AAUnderlyingObjects. It is basically like a wrapper
AA of the function AA::getAssumedUnderlyingObjects, but it can recursively do
query if the underlying object is an indirect access, such as a phi node or a select
instruction.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/include/llvm/Transforms/IPO/Attributor.h | ||
---|---|---|
5457 | You miss a public interface here, right? | |
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
11215 | If you don't use it elsewhere, just put it in the AA...Impl class below. | |
11297 | PHI and select, not load, at least not yet. Though we could do the PHI + select logic also for loads. | |
11506 | You want to allow function positions, the result is just the function. |
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
11290 | Inline and remove getAssumedUnderlyingObjects, replaces users with this AA. |
llvm/include/llvm/Transforms/IPO/Attributor.h | ||
---|---|---|
5457 | Which one? |
llvm/include/llvm/Transforms/IPO/Attributor.h | ||
---|---|---|
5463 | What happend to the other arguments: Scope and CtxI. The former at least, the latter can be useful but makes caching less effective. |
The failing test are probably because of the scope (Intra vs Inter). Other comments inlined as well.
llvm/lib/Transforms/IPO/Attributor.cpp | ||
---|---|---|
342–343 | We should make it easier for users and check the state in the foreach function. Move the debug output to the call below though. | |
343 | ||
352–353 | Adjust the rest accordingly. No need for two variables pointing to one thing. | |
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
8217 | ||
11232 | I think we should let the user pass this and update for the values the user asked, so potentially twice (intra and inter). We can add smarts to avoid one of them sometimes but I wouldn't for now. | |
11247 | We should put it in Values, this can be recursive. | |
11252 | No need to give up. Just use UO. Since this can only happen if the AA couldn't determine all underlying objects, we could probably also add an assertion instead. If the AA is not able to provide information it should just return the queried value. | |
11275 | We can just call Pred on the associatedValue. It's always correct and conservative. | |
11289 | ||
11298 | With the proposed changes above, this can be an assertion as it should always work. |
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
11259–11264 | Can't we merge this and remove Objects all together? | |
11289 | Scope can be Any. Use Intra for Intra and Inter otherwise. Maybe track what was requested so you don't eagerly compute both? | |
11317 | No need for the local objects, assert the forall call won't fail, it can't. |
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
11289 | forallUnderlyingObjects will be called after the execution of AA. We don't know the scope when we create the AA. Maybe we want to have something like the following? template <AA::ValueScope Scope> struct AAUnderlyingObjects { // ... }; using AAIntraUnderlyingObjects = AAUnderlyingObjects<AA::Intraprocedural>; using AAInterUnderlyingObjects = AAUnderlyingObjects<AA::Interprocedural>; using AAAnyUnderlyingObjects = AAUnderlyingObjects<AA::Any>; |
Run test update script please so we can verify nothing broke.
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | ||
---|---|---|
11289 | Leave it as is for now. Technically you can make it a queryAA and allow users to ask for something and we basically only update after they queried. For now this is fine. |
llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll | ||
---|---|---|
2100 | I might want to update the test case first w/o my changes. |
llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll | ||
---|---|---|
2100 | It looks like the merge of two check lines is indeed introduced in this patch. |
LG
llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll | ||
---|---|---|
2100–2118 | We know realize it's readnone, that's a good thing. |
Just a heads up: This is causing some of our clang tests to fail when run under asan/ubasn. E.g. for llvm/test/Transforms:Attributor/nosync.ll.test, we get
exit status 2
third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1158:26: runtime error: load of value 112, which is not a valid value for type 'bool'
#0 0x560ddce60c4b in llvm::Attributor::getAssumedSimplifiedValues(llvm::IRPosition const&, llvm::AbstractAttribute const*, llvm::SmallVectorImpl<llvm::AA::ValueAndContext>&, llvm::AA::ValueScope, bool&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1158:26 #1 0x560ddcf1fda2 in (anonymous namespace)::AAUnderlyingObjectsImpl::updateImpl(llvm::Attributor&)::'lambda'(llvm::SmallSetVector<llvm::Value*, 8u>&, llvm::AA::ValueScope)::operator()(llvm::SmallSetVector<llvm::Value*, 8u>&, llvm::AA::ValueScope) const third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:11235:14 #2 0x560ddcf1f4f1 in (anonymous namespace)::AAUnderlyingObjectsImpl::updateImpl(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:11272:16 #3 0x560ddce5d771 in llvm::AbstractAttribute::update(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:792:16 #4 0x560ddce69fe0 in llvm::Attributor::updateAA(llvm::AbstractAttribute&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:2302:13 #5 0x560ddce939de in llvm::AAUnderlyingObjects const& llvm::Attributor::getOrCreateAAFor<llvm::AAUnderlyingObjects>(llvm::IRPosition, llvm::AbstractAttribute const*, llvm::DepClassTy, bool, bool) third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1562:7 #6 0x560ddce5a418 in getAAFor<llvm::AAUnderlyingObjects> third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1462:12 #7 0x560ddce5a418 in getPotentialCopiesOfMemoryValue<true, llvm::LoadInst> third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:488:24 #8 0x560ddce5a418 in llvm::AA::getPotentiallyLoadedValues(llvm::Attributor&, llvm::LoadInst&, llvm::SmallSetVector<llvm::Value*, 4u>&, llvm::SmallSetVector<llvm::Instruction*, 4u>&, llvm::AbstractAttribute const&, bool&, bool) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:515:10 #9 0x560ddcef9967 in handleLoadInst third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:10572:10 #10 0x560ddcef9967 in simplifyInstruction third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:10739:14 #11 0x560ddcef9967 in genericValueTraversal third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:10796:13 #12 0x560ddcef9967 in (anonymous namespace)::AAPotentialValuesFloating::updateImpl(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:10450:5 #13 0x560ddce5d771 in llvm::AbstractAttribute::update(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:792:16 #14 0x560ddce69fe0 in llvm::Attributor::updateAA(llvm::AbstractAttribute&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:2302:13 #15 0x560ddce82d0e in llvm::AAPotentialValues const& llvm::Attributor::getOrCreateAAFor<llvm::AAPotentialValues>(llvm::IRPosition, llvm::AbstractAttribute const*, llvm::DepClassTy, bool, bool) third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1562:7 #16 0x560ddce60a77 in llvm::Attributor::getAssumedSimplifiedValues(llvm::IRPosition const&, llvm::AbstractAttribute const*, llvm::SmallVectorImpl<llvm::AA::ValueAndContext>&, llvm::AA::ValueScope, bool&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1155:7 #17 0x560ddcebe5bb in operator() third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:2129:12 #18 0x560ddcebe5bb in bool llvm::function_ref<bool (llvm::Instruction&)>::callback_fn<(anonymous namespace)::AAReturnedValuesImpl::updateImpl(llvm::Attributor&)::$_0>(long, llvm::Instruction&) third_party/llvm/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12 #19 0x560ddce66cb5 in operator() third_party/llvm/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12 #20 0x560ddce66cb5 in checkForAllInstructionsImpl(llvm::Attributor*, llvm::DenseMap<unsigned int, llvm::SmallVector<llvm::Instruction*, 8u>*, llvm::DenseMapInfo<unsigned int, void>, llvm::detail::DenseMapPair<unsigned int, llvm::SmallVector<llvm::Instruction*, 8u>*>>&, llvm::function_ref<bool (llvm::Instruction&)>, llvm::AbstractAttribute const*, llvm::AAIsDead const*, llvm::ArrayRef<unsigned int> const&, bool&, bool, bool) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1653:12 #21 0x560ddce66f5a in checkForAllInstructions third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1679:8 #22 0x560ddce66f5a in llvm::Attributor::checkForAllInstructions(llvm::function_ref<bool (llvm::Instruction&)>, llvm::AbstractAttribute const&, llvm::ArrayRef<unsigned int> const&, bool&, bool, bool) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1695:10 #23 0x560ddcebd7a3 in (anonymous namespace)::AAReturnedValuesImpl::updateImpl(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:2145:10 #24 0x560ddce5d771 in llvm::AbstractAttribute::update(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:792:16 #25 0x560ddce69fe0 in llvm::Attributor::updateAA(llvm::AbstractAttribute&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:2302:13 #26 0x560ddce95f2e in llvm::AAReturnedValues const& llvm::Attributor::getOrCreateAAFor<llvm::AAReturnedValues>(llvm::IRPosition, llvm::AbstractAttribute const*, llvm::DepClassTy, bool, bool) third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1562:7 #27 0x560ddce6683d in getAAFor<llvm::AAReturnedValues> third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1462:12 #28 0x560ddce6683d in llvm::Attributor::checkForAllReturnedValues(llvm::function_ref<bool (llvm::Value&)>, llvm::AbstractAttribute const&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1620:7 #29 0x560ddcf05211 in clampReturnedValueStates<llvm::AANoUndef, llvm::BooleanState> third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:396:10 #30 0x560ddcf05211 in (anonymous namespace)::AAReturnedFromReturnedValues<llvm::AANoUndef, (anonymous namespace)::AANoUndefImpl, llvm::BooleanState, false>::updateImpl(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:414:5 #31 0x560ddce5d771 in llvm::AbstractAttribute::update(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:792:16 #32 0x560ddce69fe0 in llvm::Attributor::updateAA(llvm::AbstractAttribute&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:2302:13 #33 0x560ddcea2ede in llvm::AANoUndef const& llvm::Attributor::getOrCreateAAFor<llvm::AANoUndef>(llvm::IRPosition, llvm::AbstractAttribute const*, llvm::DepClassTy, bool, bool) third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1562:7 #34 0x560ddcf2a82c in getAAFor<llvm::AANoUndef> third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1462:12 #35 0x560ddcf2a82c in (anonymous namespace)::AAUndefinedBehaviorImpl::updateImpl(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:3007:15 #36 0x560ddce5d771 in llvm::AbstractAttribute::update(llvm::Attributor&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:792:16 #37 0x560ddce69fe0 in llvm::Attributor::updateAA(llvm::AbstractAttribute&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:2302:13 #38 0x560ddce9d2fe in llvm::AAUndefinedBehavior const& llvm::Attributor::getOrCreateAAFor<llvm::AAUndefinedBehavior>(llvm::IRPosition, llvm::AbstractAttribute const*, llvm::DepClassTy, bool, bool) third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1562:7 #39 0x560ddce75da4 in getOrCreateAAFor<llvm::AAUndefinedBehavior> third_party/llvm/llvm-project/llvm/include/llvm/Transforms/IPO/Attributor.h:1574:12 #40 0x560ddce75da4 in llvm::Attributor::identifyDefaultAbstractAttributes(llvm::Function&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:2935:3 #41 0x560ddce79dbb in runAttributorOnFunctions(llvm::InformationCache&, llvm::SetVector<llvm::Function*, std::__u::vector<llvm::Function*, std::__u::allocator<llvm::Function*>>, llvm::DenseSet<llvm::Function*, llvm::DenseMapInfo<llvm::Function*, void>>>&, llvm::AnalysisGetter&, llvm::CallGraphUpdater&, bool, bool) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:3372:7 #42 0x560ddce792c9 in llvm::AttributorPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:3423:7 #43 0x560ddbd0a6d1 in llvm::detail::PassModel<llvm::Module, llvm::AttributorPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) third_party/llvm/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:17 #44 0x560dded5a873 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) third_party/llvm/llvm-project/llvm/include/llvm/IR/PassManager.h:517:40 #45 0x560dd9e41b4d 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) third_party/llvm/llvm-project/llvm/tools/opt/NewPMDriver.cpp:512:7 #46 0x560dd9e5c422 in main third_party/llvm/llvm-project/llvm/tools/opt/opt.cpp:726:12 #47 0x7f116010d632 in __libc_start_main (/usr/grte/v5/lib64/libc.so.6+0x61632) (BuildId: 280088eab084c30a3992a9bce5c35b44) #48 0x560dd9d69869 in _start /build/work/ab393f4ac612f9027aae6b1a7226027ba2a2/google3/blaze-out/k8-opt/bin/third_party/grte/v5_src/grte-scratch/BUILD/src/csu/../sysdeps/x86_64/start.S:120
SUMMARY: UndefinedBehaviorSanitizer: invalid-bool-load third_party/llvm/llvm-project/llvm/lib/Transforms/IPO/Attributor.cpp:1158:26 in
FileCheck error: '<stdin>' is empty.
I will see if I can get you the actual commands to reproduce this...
It appears that the actual problem is your use of an uninitialized Boolean, UsedAssumedInformation, which you declare but don't initialize on line 11231 of AttributorAttributes.cpp, then proceed to pass into other functions without initializing it first.
It still breaks asan/ubsan builds. I have committed a patch that initializes it it false. That should fix the saniziter issues, and the callees can still overwrite the value as needed.
You miss a public interface here, right?