[PATCH] D78403: Infer alignment of loads with unspecified alignment in IR/bitcode parsing.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 14:05:23 PDT 2020


efriedma created this revision.
efriedma added reviewers: jdoerfert, lebedev.ri, spatel, chandlerc.
Herald added subscribers: frgossen, grosul1, Joonsoo, kerbowa, liufengdb, lucyrfox, mgester, arpith-jacob, csigg, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini, Jim, asbirlea, jfb, dexonsmith, steven_wu, george.burgess.iv, zzheng, hiraditya, tpr, nhaehnle, jvesely, dylanmckay.
Herald added a reviewer: bollu.
Herald added a reviewer: aartbik.
Herald added a project: LLVM.

For IR generated by a compiler, this is really simple: you just take the datalayout from the beginning of the file, and apply it to all the IR later in the file. For optimization testcases that don't care about the datalayout, this is also really simple: we just use the default datalayout.

The complexity here comes from the fact that some LLVM tools allow overriding the datalayout: some tools have an explicit flag for this, some tools will infer a datalayout based on the code generation target. Supporting this properly required plumbing through a bunch of new machinery: we want to allow overriding the datalayout after the datalayout is parsed from the file, but before we use any information from it.  Therefore, IR/bitcode parsing now has a callback to allow tools to compute the datalayout at the appropriate time.

Not sure if I covered all the LLVM tools that want to use the callback. (clang? lli? Misc IR manipulation tools like llvm-link?). But this is at least enough for all the LLVM regression tests, and IR without a datalayout is not something frontends should generate.

With this patch, we impose one other new restriction: all "target triple", "target datalayout", and "source_file" directives have to be at the beginning of the file.  This should be true for all IR generated by LLVM, but hand-written IR tests sometimes stick them in weird places.

This change had some sort of weird effects for certain CodeGen regression tests: if the datalayout is overridden with a datalayout with a different program or stack address space, we now parse IR based on the overridden datalayout, instead of the one written in the file (or the default one, if none is specified).  This broke a few AVR tests, and one AMDGPU test.

Outside the CodeGen tests I mentioned, the test changes are all just fixing CHECK lines and moving around datalayout lines in weird places.

Not sure if I should try to split this.  The code changes are small enough, but the test changes are a bit large to review. I guess I could change some of the tests to explicitly specify alignment, and commit that separately?

Once this lands, it should be easy to rebase and land D77454 <https://reviews.llvm.org/D77454>, to completely eliminate loads with unspecified alignment from IR.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78403

Files:
  llvm/include/llvm/AsmParser/Parser.h
  llvm/include/llvm/Bitcode/BitcodeReader.h
  llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
  llvm/include/llvm/IRReader/IRReader.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLParser.h
  llvm/lib/AsmParser/Parser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/lib/IRReader/IRReader.cpp
  llvm/test/Analysis/BasicAA/featuretest.ll
  llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll
  llvm/test/Analysis/MemoryDependenceAnalysis/InvariantLoad.ll
  llvm/test/Analysis/MemorySSA/invariant-groups.ll
  llvm/test/Analysis/MustExecute/loop-header.ll
  llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll
  llvm/test/Analysis/ScalarEvolution/no-wrap-add-exprs.ll
  llvm/test/Analysis/TypeBasedAliasAnalysis/sink.ll
  llvm/test/Analysis/ValueTracking/deref-bitcast-of-gep.ll
  llvm/test/Bitcode/memInstructions.3.2.ll
  llvm/test/CodeGen/AArch64/falkor-hwpf.ll
  llvm/test/CodeGen/AMDGPU/invalid-alloca.ll
  llvm/test/CodeGen/AVR/call.ll
  llvm/test/CodeGen/AVR/icall-func-pointer-correct-addr-space.ll
  llvm/test/CodeGen/AVR/rust-avr-bug-37.ll
  llvm/test/CodeGen/AVR/rust-avr-bug-95.ll
  llvm/test/Feature/md_on_instruction.ll
  llvm/test/LTO/X86/strip-debug-info.ll
  llvm/test/Other/cfg_deopt_unreach.ll
  llvm/test/Transforms/CodeGenPrepare/X86/invariant.group.ll
  llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll
  llvm/test/Transforms/CorrelatedValuePropagation/phi-common-val.ll
  llvm/test/Transforms/CorrelatedValuePropagation/range.ll
  llvm/test/Transforms/DCE/basic-preservation.ll
  llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-simple.ll
  llvm/test/Transforms/DeadStoreElimination/MSSA/simple-preservation.ll
  llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll
  llvm/test/Transforms/DeadStoreElimination/simple.ll
  llvm/test/Transforms/EarlyCSE/guards.ll
  llvm/test/Transforms/EarlyCSE/invariant-loads.ll
  llvm/test/Transforms/EarlyCSE/invariant.start.ll
  llvm/test/Transforms/GVN/PRE/invariant-load.ll
  llvm/test/Transforms/GVN/PRE/load-metadata.ll
  llvm/test/Transforms/GVN/PRE/phi-translate.ll
  llvm/test/Transforms/GVN/PRE/volatile.ll
  llvm/test/Transforms/GVN/invariant.group.ll
  llvm/test/Transforms/GVN/noalias.ll
  llvm/test/Transforms/GVN/range.ll
  llvm/test/Transforms/IRCE/pre_post_loops.ll
  llvm/test/Transforms/IRCE/range_intersect_miscompile.ll
  llvm/test/Transforms/IRCE/ranges_of_different_types.ll
  llvm/test/Transforms/IRCE/unsigned_comparisons_ugt.ll
  llvm/test/Transforms/IRCE/unsigned_comparisons_ult.ll
  llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll
  llvm/test/Transforms/InstCombine/getelementptr-folding.ll
  llvm/test/Transforms/InstCombine/overflow-mul.ll
  llvm/test/Transforms/InstCombine/wcslen-3.ll
  llvm/test/Transforms/InterleavedAccess/ARM/interleaved-accesses.ll
  llvm/test/Transforms/JumpThreading/combine-metadata.ll
  llvm/test/Transforms/JumpThreading/thread-loads.ll
  llvm/test/Transforms/LICM/guards.ll
  llvm/test/Transforms/LICM/hoist-deref-load.ll
  llvm/test/Transforms/LoopIdiom/X86/popcnt.ll
  llvm/test/Transforms/LoopIdiom/X86/unordered-atomic-memcpy.ll
  llvm/test/Transforms/LoopUnroll/unroll-header-exiting-with-phis.ll
  llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll
  llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll
  llvm/test/Transforms/LoopVectorize/float-minmax-instruction-flag.ll
  llvm/test/Transforms/MemCpyOpt/load-store-to-memcpy.ll
  llvm/test/Transforms/MergeFunc/ranges-multiple.ll
  llvm/test/Transforms/MergeFunc/ranges.ll
  llvm/test/Transforms/NewGVN/metadata-nonnull.ll
  llvm/test/Transforms/NewGVN/noalias.ll
  llvm/test/Transforms/NewGVN/pr33187.ll
  llvm/test/Transforms/NewGVN/pr33204.ll
  llvm/test/Transforms/NewGVN/pr33367.ll
  llvm/test/Transforms/NewGVN/range.ll
  llvm/test/Transforms/NewGVN/refine-stores.ll
  llvm/test/Transforms/Reassociate/keep-debug-loc.ll
  llvm/test/Transforms/RewriteStatepointsForGC/deref-pointers.ll
  llvm/test/Transforms/SCCP/conditions-ranges.ll
  llvm/test/Transforms/SLPVectorizer/X86/schedule_budget.ll
  llvm/test/Transforms/SROA/basictest.ll
  llvm/test/Transforms/SafeStack/X86/call.ll
  llvm/test/Transforms/SeparateConstOffsetFromGEP/test-add-sub-separation.ll
  llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll
  llvm/test/Transforms/Util/assume-builder.ll
  llvm/test/Verifier/unsized-types-alloca.ll
  llvm/test/Verifier/unsized-types-load.ll
  llvm/test/Verifier/unsized-types-store.ll
  llvm/test/Verifier/unsized-types.ll
  llvm/tools/llc/llc.cpp
  llvm/tools/llvm-as/llvm-as.cpp
  llvm/tools/opt/opt.cpp
  mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
  polly/test/ForwardOpTree/forward_hoisted.ll
  polly/test/ForwardOpTree/forward_into_region_redundant_use.ll
  polly/test/ForwardOpTree/forward_load.ll
  polly/test/ForwardOpTree/forward_load_differentarray.ll
  polly/test/ForwardOpTree/forward_load_double_write.ll
  polly/test/ForwardOpTree/forward_load_fromloop.ll
  polly/test/ForwardOpTree/forward_load_indirect.ll
  polly/test/ForwardOpTree/forward_load_memset_before.ll
  polly/test/ForwardOpTree/forward_load_tripleuse.ll
  polly/test/ForwardOpTree/forward_load_unrelatedunusual.ll
  polly/test/ForwardOpTree/forward_phi_load.ll
  polly/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll
  polly/test/ScopInfo/granularity_scalar-indep.ll
  polly/test/ScopInfo/granularity_scalar-indep_epilogue.ll
  polly/test/ScopInfo/granularity_scalar-indep_epilogue_last.ll
  polly/test/ScopInfo/granularity_scalar-indep_noepilogue.ll
  polly/test/ScopInfo/granularity_scalar-indep_ordered-2.ll
  polly/test/ScopInfo/granularity_scalar-indep_ordered.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78403.258420.patch
Type: text/x-patch
Size: 193368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200417/4f3d638a/attachment-0001.bin>


More information about the llvm-commits mailing list