[all-commits] [llvm/llvm-project] 45a291: [Dominators] check indirect branches of callbr

Nick Desaulniers via All-commits all-commits at lists.llvm.org
Thu Feb 16 18:04:01 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 45a291b5f609fc7edd8c526772e491d68b210dbe
      https://github.com/llvm/llvm-project/commit/45a291b5f609fc7edd8c526772e491d68b210dbe
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M llvm/include/llvm/IR/Dominators.h
    M llvm/lib/IR/Dominators.cpp
    M llvm/lib/IR/Instruction.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    M llvm/test/Transforms/Coroutines/coro-debug.ll
    M llvm/test/Transforms/InstCombine/freeze.ll
    M llvm/test/Transforms/Reassociate/callbr.ll
    M llvm/test/Verifier/callbr.ll
    M llvm/test/Verifier/dominates.ll
    M llvm/unittests/IR/DominatorTreeTest.cpp

  Log Message:
  -----------
  [Dominators] check indirect branches of callbr

This will be necessary to support outputs from asm goto along indirect
edges.

Test via:
  $ pushd llvm/build; ninja IRTests; popd
  $ ./llvm/build/unittests/IR/IRTests \
    --gtest_filter=DominatorTree.CallBrDomination

Also, return nullptr in Instruction::getInsertionPointAfterDef for
CallBrInst as was recommened in
https://reviews.llvm.org/D135997#3991427.  The following phab review was
folded into this commit: https://reviews.llvm.org/D140166

Link: Link: https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8

Reviewed By: void, efriedma, ChuanqiXu, MaskRay

Differential Revision: https://reviews.llvm.org/D135997


  Commit: fb471158aa0da2690beb3be3af2618af2f5bf4df
      https://github.com/llvm/llvm-project/commit/fb471158aa0da2690beb3be3af2618af2f5bf4df
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
    M llvm/include/llvm/CodeGen/MachinePassRegistry.def
    M llvm/include/llvm/CodeGen/Passes.h
    M llvm/include/llvm/InitializePasses.h
    M llvm/lib/CodeGen/CMakeLists.txt
    A llvm/lib/CodeGen/CallBrPrepare.cpp
    M llvm/lib/CodeGen/CodeGen.cpp
    M llvm/lib/CodeGen/TargetPassConfig.cpp
    A llvm/test/CodeGen/AArch64/callbr-prepare.ll
    M llvm/tools/opt/opt.cpp
    M llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn

  Log Message:
  -----------
  [llvm] boilerplate for new callbrprepare codegen IR pass

Because this pass is to be a codegen pass, it must use the legacy pass
manager.

Link: https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8

Reviewed By: aeubanks, void

Differential Revision: https://reviews.llvm.org/D139861


  Commit: 0a39af0eb72d0fb1cce592aa5e5a1e3bd08110be
      https://github.com/llvm/llvm-project/commit/0a39af0eb72d0fb1cce592aa5e5a1e3bd08110be
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M llvm/lib/CodeGen/CallBrPrepare.cpp
    M llvm/test/CodeGen/AArch64/callbr-prepare.ll

  Log Message:
  -----------
  [llvm][CallBrPrepare] split critical edges

If we have a CallBrInst with output that's used, we need to split
critical edges so that we have some place to insert COPYs for physregs
to virtregs.

Part 2a of
https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8.

Test cases and logic re-purposed from D138078.

Reviewed By: efriedma, void, jyknight

Differential Revision: https://reviews.llvm.org/D139872


  Commit: 094190c2f52900d9d5d26dba9522e70030cc00a1
      https://github.com/llvm/llvm-project/commit/094190c2f52900d9d5d26dba9522e70030cc00a1
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M llvm/include/llvm/IR/Intrinsics.td
    M llvm/lib/CodeGen/CallBrPrepare.cpp
    M llvm/lib/IR/Verifier.cpp
    M llvm/test/CodeGen/AArch64/callbr-prepare.ll
    M llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
    M llvm/test/Verifier/callbr.ll

  Log Message:
  -----------
  [llvm][CallBrPrepare] add llvm.callbr.landingpad intrinsic

Insert a new intrinsic call after splitting critical edges, and verify
it. Later commits will update the SSA values to use this new value along
indirect branches rather than the callbr's value, and have SelectionDAG
consume this new value.

Part 2b of
https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8.

Reviewed By: efriedma, jyknight

Differential Revision: https://reviews.llvm.org/D139883


  Commit: 28d45c843cd07514c9a7260d285ff59e14280ecf
      https://github.com/llvm/llvm-project/commit/28d45c843cd07514c9a7260d285ff59e14280ecf
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M llvm/lib/CodeGen/CallBrPrepare.cpp
    M llvm/test/CodeGen/AArch64/callbr-prepare.ll

  Log Message:
  -----------
  [llvm][CallBrPrepare] use SSAUpdater to use intrinsic value

Now that we've inserted a call to an intrinsic, we need to update
certain previous uses of CallBrInst values to use the value of this
intrinsic instead.

There are 3 cases to handle:
1. The @llvm.callbr.landingpad.<type>() intrinsic call is in the same
   BasicBlock as the use of the callbr we're replacing.
2. The use is dominated by the direct destination.
3. The use is not dominated by the direct destination, and may or may
   not be dominated by the indirect destination.

Part 2c of
https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8.

Reviewed By: efriedma, void, jyknight

Differential Revision: https://reviews.llvm.org/D139970


  Commit: 5cc1016a57b38595262026ba3c482f6108b12e5b
      https://github.com/llvm/llvm-project/commit/5cc1016a57b38595262026ba3c482f6108b12e5b
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
    A llvm/test/CodeGen/AArch64/callbr-asm-outputs-indirect-isel.ll
    A llvm/test/CodeGen/PowerPC/callbr-asm-outputs-indirect-isel.ll
    A llvm/test/CodeGen/X86/callbr-asm-outputs-indirect-isel-m32.ll
    A llvm/test/CodeGen/X86/callbr-asm-outputs-indirect-isel.ll

  Log Message:
  -----------
  [llvm][SelectionDAGBuilder] codegen callbr.landingpad intrinsic

Given a CallBrInst, retain its first virtual register in SelectionDagBuilder's
FunctionLoweringInfo if there's corresponding landingpad. Walk the list
of COPY MachineInstr to find the original virtual and physical registers
defined by the INLINEASM_BR MachineInst.

Test cases from https://reviews.llvm.org/D139565.
Link: https://github.com/llvm/llvm-project/issues/59538

Part 3 from
https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8

Follow up patches still need to wire up CallBrPrepare into the pass
pipelines.

Reviewed By: efriedma, void

Differential Revision: https://reviews.llvm.org/D140160


  Commit: a3a84c9e2511c06f1c47af76e26581b674149b82
      https://github.com/llvm/llvm-project/commit/a3a84c9e2511c06f1c47af76e26581b674149b82
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M llvm/docs/LangRef.rst
    M llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
    M llvm/lib/CodeGen/MachineVerifier.cpp
    M llvm/lib/CodeGen/TargetPassConfig.cpp
    M llvm/test/CodeGen/AArch64/O0-pipeline.ll
    M llvm/test/CodeGen/AArch64/O3-pipeline.ll
    M llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
    M llvm/test/CodeGen/ARM/O3-pipeline.ll
    M llvm/test/CodeGen/LoongArch/O0-pipeline.ll
    M llvm/test/CodeGen/LoongArch/opt-pipeline.ll
    M llvm/test/CodeGen/PowerPC/O0-pipeline.ll
    M llvm/test/CodeGen/PowerPC/O3-pipeline.ll
    M llvm/test/CodeGen/RISCV/O0-pipeline.ll
    M llvm/test/CodeGen/RISCV/O3-pipeline.ll
    M llvm/test/CodeGen/X86/O0-pipeline.ll
    M llvm/test/CodeGen/X86/callbr-asm-outputs-pred-succ.ll
    M llvm/test/CodeGen/X86/callbr-asm-outputs.ll
    M llvm/test/CodeGen/X86/opt-pipeline.ll

  Log Message:
  -----------
  [llvm] add CallBrPrepare pass to pipelines

Capstone of
https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8

Clang changes are still necessary to enable the use of outputs along
indirect edges of asm goto statements.

Link: https://github.com/llvm/llvm-project/issues/53562

Reviewed By: void

Differential Revision: https://reviews.llvm.org/D140180


  Commit: b1bc723dfe9734a8b3157dbf50328b5d62436bd6
      https://github.com/llvm/llvm-project/commit/b1bc723dfe9734a8b3157dbf50328b5d62436bd6
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M clang/lib/CodeGen/CGStmt.cpp

  Log Message:
  -----------
  [Clang] refactor CodeGenFunction::EmitAsmStmt NFC

Prerequisite to further modifications in D136497.

Basically, there is a large body of code in CodeGenFunction::EmitAsmStmt
for emitting stores of outputs. We want to be able to repeat this logic,
for each destination of a callbr (rather than just the default
destination which is what the code currently does).

Also does some smaller cleanups like whitespace cleanups, and removing
pointless casts.

Reviewed By: void, jyknight

Differential Revision: https://reviews.llvm.org/D137113


  Commit: 329ef60f3e21fd6845e8e8b0da405cae7eb27267
      https://github.com/llvm/llvm-project/commit/329ef60f3e21fd6845e8e8b0da405cae7eb27267
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M clang/docs/LanguageExtensions.rst
    M clang/docs/ReleaseNotes.rst
    M clang/lib/CodeGen/CGStmt.cpp
    M clang/test/CodeGen/asm-goto.c
    A clang/test/CodeGen/asm-goto2.c
    M clang/test/Modules/asm-goto.c

  Log Message:
  -----------
  [Clang] support for outputs along indirect edges of asm goto

Initial support for asm goto w/ outputs (D69876) only supported outputs
along the "default" (aka "fallthrough") edge.

We can support outputs along all edges by repeating the same pattern of
stores along the indirect edges that we allready do for the default
edge.  One complication is that these indirect edges may be critical
edges which would need to be split. Another issue is that mid-codgen of
LLVM IR, the control flow graph might not reflect the control flow of
the final function.

To avoid this "chicken and the egg" problem assume that any given
indirect edge may become a critical edge, and pro-actively split it.
This is unnecessary if the edge does not become critical, but LLVM will
optimize such cases via tail duplication.

Fixes: https://github.com/llvm/llvm-project/issues/53562

Reviewed By: void

Differential Revision: https://reviews.llvm.org/D136497


  Commit: af6656338db365fde6c0b0e53db8f98aa8ed59d4
      https://github.com/llvm/llvm-project/commit/af6656338db365fde6c0b0e53db8f98aa8ed59d4
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M clang/lib/Analysis/UninitializedValues.cpp
    M clang/test/Analysis/uninit-asm-goto.cpp

  Log Message:
  -----------
  [clang] fix -Wuninitialized for asm goto outputs on indirect edges.

Now that we support outputs from asm goto along indirect edges, we can
remove/revert some code that was added to help warn about the previous
limitation that outputs were not supported along indirect edges.

Reverts some code added in:
commit 72aa619a7fe0 ("Warn of uninitialized variables on asm goto's indirect branch")
commit 3a604fdbcd5f ("[Clang][CFG] check children statements of asm goto")
But keeps+updates the tests.

Link: https://github.com/llvm/llvm-project/issues/53562

Reviewed By: void

Differential Revision: https://reviews.llvm.org/D140508


  Commit: 54186d33c3a0d4834d2e5f95640b63677f5b5142
      https://github.com/llvm/llvm-project/commit/54186d33c3a0d4834d2e5f95640b63677f5b5142
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2023-02-16 (Thu, 16 Feb 2023)

  Changed paths:
    M clang/docs/LanguageExtensions.rst
    M clang/include/clang/Basic/Features.def
    M clang/test/Parser/asm-goto.c

  Log Message:
  -----------
  [clang] add __has_extension(gnu_asm_goto_with_outputs_full)

Also move the line about __has_extension(gnu_asm_goto_with_outputs) so
that it is more generally about asm goto, not the paragraph on symbolic
references.

Reviewed By: efriedma, void

Differential Revision: https://reviews.llvm.org/D143205


Compare: https://github.com/llvm/llvm-project/compare/df277ec67efd...54186d33c3a0


More information about the All-commits mailing list