[IR] Don't use blockaddresses as callbr arguments
authorNikita Popov <npopov@redhat.com>
Thu, 7 Jul 2022 10:27:43 +0000 (12:27 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 15 Jul 2022 08:18:17 +0000 (10:18 +0200)
commit2a721374aef326d4668f750d341c86d1aa1a0309
tree234adf3c0ee20439eb8077b5a0702b4d88f35efa
parentcae5462a2caa4a14516d3935d2ca3a1f1d0522c9
[IR] Don't use blockaddresses as callbr arguments

Following some recent discussions, this changes the representation
of callbrs in IR. The current blockaddress arguments are replaced
with `!` label constraints that refer directly to callbr indirect
destinations:

    ; Before:
    %res = callbr i8* asm "", "=r,r,i"(i8* %x, i8* blockaddress(@test8, %foo))
    to label %asm.fallthrough [label %foo]
    ; After:
    %res = callbr i8* asm "", "=r,r,!i"(i8* %x)
    to label %asm.fallthrough [label %foo]

The benefit of this is that we can easily update the successors of
a callbr, without having to worry about also updating blockaddress
references. This should allow us to remove some limitations:

* Allow unrolling/peeling/rotation of callbr, or any other
  clone-based optimizations
  (https://github.com/llvm/llvm-project/issues/41834)
* Allow duplicate successors
  (https://github.com/llvm/llvm-project/issues/45248)

This is just the IR representation change though, I will follow up
with patches to remove limtations in various transformation passes
that are no longer needed.

Differential Revision: https://reviews.llvm.org/D129288
74 files changed:
clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/asm-goto.c
clang/test/CodeGen/asm.c
clang/test/Modules/asm-goto.c
llvm/docs/LangRef.rst
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/IR/InlineAsm.h
llvm/include/llvm/IR/Instructions.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/IR/InlineAsm.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Analysis/BasicAA/pr52735.ll
llvm/test/Assembler/call-arg-is-callee.ll
llvm/test/Assembler/inline-asm-constraint-error.ll
llvm/test/Bitcode/callbr.ll
llvm/test/CodeGen/AArch64/callbr-asm-label.ll
llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll
llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
llvm/test/CodeGen/PowerPC/ppc64-inlineasm-clobber.ll
llvm/test/CodeGen/SystemZ/asm-20.ll
llvm/test/CodeGen/X86/callbr-asm-bb-exports.ll
llvm/test/CodeGen/X86/callbr-asm-blockplacement.ll
llvm/test/CodeGen/X86/callbr-asm-branch-folding.ll
llvm/test/CodeGen/X86/callbr-asm-destinations.ll
llvm/test/CodeGen/X86/callbr-asm-errors.ll [deleted file]
llvm/test/CodeGen/X86/callbr-asm-instr-scheduling.ll
llvm/test/CodeGen/X86/callbr-asm-kill.mir
llvm/test/CodeGen/X86/callbr-asm-label-addr.ll
llvm/test/CodeGen/X86/callbr-asm-obj-file.ll
llvm/test/CodeGen/X86/callbr-asm-outputs-pred-succ.ll
llvm/test/CodeGen/X86/callbr-asm-outputs.ll
llvm/test/CodeGen/X86/callbr-asm-phi-placement.ll
llvm/test/CodeGen/X86/callbr-asm-sink.ll
llvm/test/CodeGen/X86/callbr-asm.ll
llvm/test/CodeGen/X86/callbr-codegenprepare.ll
llvm/test/CodeGen/X86/inline-asm-pic.ll
llvm/test/CodeGen/X86/shrinkwrap-callbr.ll
llvm/test/CodeGen/X86/speculation-hardening-sls.ll
llvm/test/CodeGen/X86/tail-dup-asm-goto.ll
llvm/test/Instrumentation/MemorySanitizer/msan_asm_conservative.ll
llvm/test/Transforms/CallSiteSplitting/callsite-split-callbr.ll
llvm/test/Transforms/CodeExtractor/PartialInlinePGOMultiRegion.ll
llvm/test/Transforms/Coroutines/coro-debug.ll
llvm/test/Transforms/GVN/callbr-loadpre-critedge.ll
llvm/test/Transforms/GVN/callbr-scalarpre-critedge.ll
llvm/test/Transforms/GVN/critical-edge-split-failure.ll
llvm/test/Transforms/IROutliner/illegal-callbr.ll
llvm/test/Transforms/Inline/blockaddress.ll
llvm/test/Transforms/Inline/callbr.ll
llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
llvm/test/Transforms/LICM/callbr-crash.ll
llvm/test/Transforms/LoopDeletion/two-predecessors.ll
llvm/test/Transforms/LoopRotate/callbr.ll
llvm/test/Transforms/LoopStrengthReduce/callbr-critical-edge-splitting.ll
llvm/test/Transforms/LoopStrengthReduce/callbr-critical-edge-splitting2.ll
llvm/test/Transforms/LoopStrengthReduce/remove_scev_indvars.ll
llvm/test/Transforms/LoopUnroll/callbr.ll
llvm/test/Transforms/PGOProfile/callbr.ll
llvm/test/Transforms/SimpleLoopUnswitch/not-safe-to-clone.ll
llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
llvm/test/Transforms/SimplifyCFG/jump-threading.ll
llvm/test/Verifier/callbr.ll
llvm/test/Verifier/dominates.ll
llvm/test/tools/llvm-diff/callbr.ll
llvm/test/tools/llvm-diff/phinode.ll
llvm/test/tools/llvm-reduce/remove-function-arguments-of-funcs-used-in-blockaddress.ll
llvm/unittests/IR/InstructionsTest.cpp
polly/test/ScopDetect/callbr.ll