mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-23 19:59:57 +00:00
f37c8a6b19
This was a real restriction in the original version of SinkIfThenCodeToEnd. Now it's been rewritten, the restriction can be lifted. As part of this, we handle a very common and useful case where one of the incoming branches is actually conditional. Consider: if (a) x(1); else if (b) x(2); This produces the following CFG: [if] / \ [x(1)] [if] | | \ | | \ | [x(2)] | \ | / [ end ] [end] has two unconditional predecessor arcs and one conditional. The conditional refers to the implicit empty 'else' arc. This same pattern can also be caused by an empty default block in a switch. We can't sink the call to x() down to end because no call to x() happens on the third incoming arc (assume that x() has sideeffects for the sake of argument; if something is safe to speculate we could indeed sink nevertheless but this cannot happen in the general case and causes many extra selects). We are now able to detect this case and split off the unconditional arcs to a common successor: [if] / \ [x(1)] [if] | | \ | | \ | [x(2)] | \ / | [sink.split] | \ / [ end ] Now we can sink the call to x() into %sink.split. This can cause significant code simplification in many testcases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280364 91177308-0d34-0410-b5e6-96231b3b80d8
34 lines
1.3 KiB
LLVM
34 lines
1.3 KiB
LLVM
; RUN: llc < %s -mtriple=aarch64-none-linux-gnu -stop-after branch-folder | FileCheck %s
|
|
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
|
|
|
|
; Function Attrs: norecurse nounwind
|
|
define void @foo(i32 %a, i32 %b, float* nocapture %foo_arr) #0 {
|
|
; CHECK: (load 4 from %ir.arrayidx1.{{i[1-2]}})
|
|
entry:
|
|
%cmp = icmp sgt i32 %a, 0
|
|
br i1 %cmp, label %if.then, label %if.end
|
|
|
|
if.then: ; preds = %entry
|
|
%0 = load float, float* %foo_arr, align 4
|
|
%arrayidx1.i1 = getelementptr inbounds float, float* %foo_arr, i64 1
|
|
%1 = load float, float* %arrayidx1.i1, align 4
|
|
%sub.i = fsub float %0, %1
|
|
store float %sub.i, float* %foo_arr, align 4
|
|
br label %if.end3
|
|
|
|
if.end: ; preds = %entry
|
|
%cmp1 = icmp sgt i32 %b, 0
|
|
br i1 %cmp1, label %if.then2, label %if.end3
|
|
|
|
if.then2: ; preds = %if.end
|
|
%2 = load float, float* %foo_arr, align 4
|
|
%arrayidx1.i2 = getelementptr inbounds float, float* %foo_arr, i64 1
|
|
%3 = load float, float* %arrayidx1.i2, align 4
|
|
%sub.i3 = fsub float %2, %3
|
|
store float %sub.i3, float* %foo_arr, align 4
|
|
br label %if.end3
|
|
|
|
if.end3: ; preds = %if.then2, %if.end, %if.then
|
|
ret void
|
|
}
|