mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
69 lines
1.7 KiB
C
69 lines
1.7 KiB
C
fn int* elvis(int *x, int *y)
|
|
{
|
|
return x ?: y;
|
|
}
|
|
|
|
|
|
fn int* elvis2(int *x, int *y)
|
|
{
|
|
return x ?: (y ?: x);
|
|
}
|
|
|
|
fn bool elvis3(bool x, bool y)
|
|
{
|
|
return x ?: y;
|
|
}
|
|
|
|
|
|
// #expect: elvis.ll
|
|
|
|
define i32* @elvis.elvis(i32* %0, i32* %1) #0 {
|
|
entry:
|
|
%ptrbool = icmp ne i32* %0, null
|
|
br i1 %ptrbool, label %cond.phi, label %cond.rhs
|
|
|
|
cond.rhs: ; preds = %entry
|
|
br label %cond.phi
|
|
|
|
cond.phi: ; preds = %cond.rhs, %entry
|
|
%val = phi i32* [ %0, %entry ], [ %1, %cond.rhs ]
|
|
ret i32* %val
|
|
}
|
|
|
|
define i32* @elvis.elvis2(i32* %0, i32* %1) #0 {
|
|
entry:
|
|
%ptrbool = icmp ne i32* %0, null
|
|
br i1 %ptrbool, label %cond.phi3, label %cond.rhs
|
|
|
|
cond.rhs: ; preds = %entry
|
|
%ptrbool1 = icmp ne i32* %1, null
|
|
br i1 %ptrbool1, label %cond.phi, label %cond.rhs2
|
|
|
|
cond.rhs2: ; preds = %cond.rhs
|
|
br label %cond.phi
|
|
|
|
cond.phi: ; preds = %cond.rhs2, %cond.rhs
|
|
%val = phi i32* [ %1, %cond.rhs ], [ %0, %cond.rhs2 ]
|
|
br label %cond.phi3
|
|
|
|
cond.phi3: ; preds = %cond.phi, %entry
|
|
%val4 = phi i32* [ %0, %entry ], [ %val, %cond.phi ]
|
|
ret i32* %val4
|
|
}
|
|
|
|
define zeroext i8 @elvis.elvis3(i8 zeroext %0, i8 zeroext %1) #0 {
|
|
entry:
|
|
%2 = trunc i8 %0 to i1
|
|
br i1 %2, label %cond.phi, label %cond.rhs
|
|
|
|
cond.rhs: ; preds = %entry
|
|
%3 = trunc i8 %1 to i1
|
|
br label %cond.phi
|
|
|
|
cond.phi: ; preds = %cond.rhs, %entry
|
|
%val = phi i1 [ %2, %entry ], [ %3, %cond.rhs ]
|
|
%4 = zext i1 %val to i8
|
|
ret i8 %4
|
|
}
|
|
|
|
attributes #0 = { nounwind } |