Nikita Popov 2a721374ae [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
2022-07-15 10:18:17 +02:00

55 lines
1.7 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
; RUN: opt -callsite-splitting -S -o - < %s | FileCheck %s
; Check that we can split the critical edge between Top and CallSiteBB, and
; rewrite the first callbr's indirect destination correctly.
define void @caller() {
; CHECK-LABEL: define {{[^@]+}}@caller() {
; CHECK-NEXT: Top:
; CHECK-NEXT: callbr void asm sideeffect "", "!i,~{dirflag},~{fpsr},~{flags}"()
; CHECK-NEXT: to label [[NEXTCOND:%.*]] [label %Top.split]
; CHECK: Top.split:
; CHECK-NEXT: call void @callee(i1 false)
; CHECK-NEXT: br label [[CALLSITEBB:%.*]]
; CHECK: NextCond:
; CHECK-NEXT: br label [[NEXTCOND_SPLIT:%.*]]
; CHECK: NextCond.split:
; CHECK-NEXT: call void @callee(i1 true)
; CHECK-NEXT: br label [[CALLSITEBB]]
; CHECK: CallSiteBB:
; CHECK-NEXT: [[PHI:%.*]] = phi i1 [ false, [[TOP_SPLIT:%.*]] ], [ true, [[NEXTCOND_SPLIT]] ]
; CHECK-NEXT: callbr void asm sideeffect "", "r,!i,~{dirflag},~{fpsr},~{flags}"(i1 [[PHI]])
; CHECK-NEXT: to label [[END:%.*]] [label %End2]
; CHECK: End:
; CHECK-NEXT: ret void
; CHECK: End2:
; CHECK-NEXT: ret void
;
Top:
callbr void asm sideeffect "", "!i,~{dirflag},~{fpsr},~{flags}"()
to label %NextCond [label %CallSiteBB]
NextCond:
br label %CallSiteBB
CallSiteBB:
%phi = phi i1 [0, %Top],[1, %NextCond]
call void @callee(i1 %phi)
callbr void asm sideeffect "", "r,!i,~{dirflag},~{fpsr},~{flags}"(i1 %phi)
to label %End [label %End2]
End:
ret void
End2:
ret void
}
define void @callee(i1 %b) {
; CHECK-LABEL: define {{[^@]+}}@callee
; CHECK-SAME: (i1 [[B:%.*]]) {
; CHECK-NEXT: ret void
;
ret void
}