[llvm-dev] minimal C code that would generate IR code using phi
Krzysztof Parzyszek via llvm-dev
llvm-dev at lists.llvm.org
Fri Jan 25 09:05:40 PST 2019
On 1/25/2019 10:55 AM, Peng Yu via llvm-dev wrote:
>
> Does anybody have a minimal C code that would generate IR code using
> phi? Thanks.
I don't know if this is minimal, but it's short:
--- p.c ---
int bar(int a);
int foo(int a) {
return a > 0 ? bar(a-1) : -bar(0);
}
-----------
$ clang -S -emit-llvm -O2 p.c -o -
; ModuleID = 'p.c'
source_filename = "p.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: nounwind uwtable
define dso_local i32 @foo(i32 %a) local_unnamed_addr #0 {
entry:
%cmp = icmp sgt i32 %a, 0
br i1 %cmp, label %cond.true, label %cond.false
cond.true: ; preds = %entry
%sub = add nsw i32 %a, -1
%call = tail call i32 @bar(i32 %sub) #2
br label %cond.end
cond.false: ; preds = %entry
%call1 = tail call i32 @bar(i32 0) #2
%sub2 = sub nsw i32 0, %call1
br label %cond.end
cond.end: ; preds = %cond.false,
%cond.true
%cond = phi i32 [ %call, %cond.true ], [ %sub2, %cond.false ]
ret i32 %cond
}
[...]
-Krzysztof
More information about the llvm-dev
mailing list