mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Make "?:" lower in the frontend.
This commit is contained in:
@@ -20,49 +20,75 @@ fn bool elvis3(bool x, bool y)
|
||||
|
||||
define ptr @elvis.elvis(ptr %0, ptr %1) #0 {
|
||||
entry:
|
||||
%ptrbool = icmp ne ptr %0, null
|
||||
br i1 %ptrbool, label %cond.phi, label %cond.rhs
|
||||
%.anon = alloca ptr, align 8
|
||||
store ptr %0, ptr %.anon, align 8
|
||||
%i2b = icmp ne ptr %0, null
|
||||
br i1 %i2b, label %cond.lhs, label %cond.rhs
|
||||
|
||||
cond.lhs: ; preds = %entry
|
||||
%2 = load ptr, ptr %.anon, align 8
|
||||
br label %cond.phi
|
||||
|
||||
cond.rhs: ; preds = %entry
|
||||
br label %cond.phi
|
||||
|
||||
cond.phi: ; preds = %cond.rhs, %entry
|
||||
%val = phi ptr [ %0, %entry ], [ %1, %cond.rhs ]
|
||||
cond.phi: ; preds = %cond.rhs, %cond.lhs
|
||||
%val = phi ptr [ %2, %cond.lhs ], [ %1, %cond.rhs ]
|
||||
ret ptr %val
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind uwtable
|
||||
define ptr @elvis.elvis2(ptr %0, ptr %1) #0 {
|
||||
entry:
|
||||
%ptrbool = icmp ne ptr %0, null
|
||||
br i1 %ptrbool, label %cond.phi3, label %cond.rhs
|
||||
%.anon = alloca ptr, align 8
|
||||
%.anon1 = alloca ptr, align 8
|
||||
store ptr %0, ptr %.anon, align 8
|
||||
%i2b = icmp ne ptr %0, null
|
||||
br i1 %i2b, label %cond.lhs, label %cond.rhs
|
||||
|
||||
cond.lhs: ; preds = %entry
|
||||
%2 = load ptr, ptr %.anon, align 8
|
||||
br label %cond.phi5
|
||||
|
||||
cond.rhs: ; preds = %entry
|
||||
%ptrbool1 = icmp ne ptr %1, null
|
||||
br i1 %ptrbool1, label %cond.phi, label %cond.rhs2
|
||||
store ptr %1, ptr %.anon1, align 8
|
||||
%i2b2 = icmp ne ptr %1, null
|
||||
br i1 %i2b2, label %cond.lhs3, label %cond.rhs4
|
||||
|
||||
cond.rhs2: ; preds = %cond.rhs
|
||||
cond.lhs3: ; preds = %cond.rhs
|
||||
%3 = load ptr, ptr %.anon1, align 8
|
||||
br label %cond.phi
|
||||
|
||||
cond.phi: ; preds = %cond.rhs2, %cond.rhs
|
||||
%val = phi ptr [ %1, %cond.rhs ], [ %0, %cond.rhs2 ]
|
||||
br label %cond.phi3
|
||||
cond.rhs4: ; preds = %cond.rhs
|
||||
br label %cond.phi
|
||||
|
||||
cond.phi3: ; preds = %cond.phi, %entry
|
||||
%val4 = phi ptr [ %0, %entry ], [ %val, %cond.phi ]
|
||||
ret ptr %val4
|
||||
cond.phi: ; preds = %cond.rhs4, %cond.lhs3
|
||||
%val = phi ptr [ %3, %cond.lhs3 ], [ %0, %cond.rhs4 ]
|
||||
br label %cond.phi5
|
||||
|
||||
cond.phi5: ; preds = %cond.phi, %cond.lhs
|
||||
%val6 = phi ptr [ %2, %cond.lhs ], [ %val, %cond.phi ]
|
||||
ret ptr %val6
|
||||
}
|
||||
|
||||
define zeroext i8 @elvis.elvis3(i8 zeroext %0, i8 zeroext %1) #0 {
|
||||
entry:
|
||||
%.anon = alloca i8, align 1
|
||||
store i8 %0, ptr %.anon, align 1
|
||||
%2 = trunc i8 %0 to i1
|
||||
br i1 %2, label %cond.phi, label %cond.rhs
|
||||
br i1 %2, label %cond.lhs, label %cond.rhs
|
||||
|
||||
cond.rhs: ; preds = %entry
|
||||
%3 = trunc i8 %1 to i1
|
||||
cond.lhs: ; preds = %entry
|
||||
%3 = load i8, ptr %.anon, align 1
|
||||
%4 = trunc i8 %3 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
|
||||
cond.rhs: ; preds = %entry
|
||||
%5 = trunc i8 %1 to i1
|
||||
br label %cond.phi
|
||||
|
||||
cond.phi: ; preds = %cond.rhs, %cond.lhs
|
||||
%val = phi i1 [ %4, %cond.lhs ], [ %5, %cond.rhs ]
|
||||
%6 = zext i1 %val to i8
|
||||
ret i8 %6
|
||||
}
|
||||
|
||||
@@ -19,94 +19,88 @@ define void @ternary_bool.main() #0 {
|
||||
entry:
|
||||
%b = alloca i8, align 1
|
||||
%c = alloca ptr, align 8
|
||||
%.anon = alloca i8, align 1
|
||||
%.anon13 = alloca i8, align 1
|
||||
store i8 1, ptr %b, align 1
|
||||
store ptr %b, ptr %c, align 8
|
||||
%0 = load ptr, ptr %c, align 8
|
||||
%1 = load i8, ptr %0, align 1
|
||||
%2 = trunc i8 %1 to i1
|
||||
br i1 %2, label %cond.lhs, label %cond.rhs
|
||||
|
||||
cond.lhs: ; preds = %entry
|
||||
%3 = load ptr, ptr %c, align 8
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = trunc i8 %4 to i1
|
||||
br label %cond.phi
|
||||
|
||||
cond.rhs: ; preds = %entry
|
||||
%6 = load ptr, ptr %c, align 8
|
||||
%7 = load i8, ptr %6, align 1
|
||||
%8 = trunc i8 %7 to i1
|
||||
br label %cond.phi
|
||||
|
||||
cond.phi: ; preds = %cond.rhs, %cond.lhs
|
||||
%val = phi i1 [ %5, %cond.lhs ], [ %8, %cond.rhs ]
|
||||
br i1 %val, label %if.then, label %if.exit
|
||||
|
||||
if.then: ; preds = %cond.phi
|
||||
call void (ptr, ...) @printf(ptr @.str)
|
||||
br label %if.exit
|
||||
|
||||
if.exit: ; preds = %if.then, %cond.phi
|
||||
%9 = load i8, ptr %b, align 1
|
||||
%10 = trunc i8 %9 to i1
|
||||
br i1 %10, label %cond.lhs1, label %cond.rhs2
|
||||
|
||||
cond.lhs1: ; preds = %if.exit
|
||||
%11 = load i8, ptr %b, align 1
|
||||
%12 = trunc i8 %11 to i1
|
||||
br label %cond.phi3
|
||||
|
||||
cond.rhs2: ; preds = %if.exit
|
||||
%13 = load i8, ptr %b, align 1
|
||||
%14 = trunc i8 %13 to i1
|
||||
br label %cond.phi3
|
||||
|
||||
cond.phi3: ; preds = %cond.rhs2, %cond.lhs1
|
||||
%val4 = phi i1 [ %12, %cond.lhs1 ], [ %14, %cond.rhs2 ]
|
||||
br i1 %val4, label %if.then5, label %if.exit6
|
||||
|
||||
if.then5: ; preds = %cond.phi3
|
||||
call void (ptr, ...) @printf(ptr @.str.1)
|
||||
br label %if.exit6
|
||||
|
||||
if.exit6: ; preds = %if.then5, %cond.phi3
|
||||
%15 = load ptr, ptr %c, align 8
|
||||
%16 = load i8, ptr %15, align 1
|
||||
store i8 %16, ptr %.anon, align 1
|
||||
%17 = trunc i8 %16 to i1
|
||||
br i1 %17, label %cond.phi8, label %cond.rhs7
|
||||
|
||||
cond.rhs7: ; preds = %if.exit6
|
||||
%18 = load ptr, ptr %c, align 8
|
||||
%19 = load i8, ptr %18, align 1
|
||||
%20 = trunc i8 %19 to i1
|
||||
br label %cond.phi8
|
||||
|
||||
cond.phi8: ; preds = %cond.rhs7, %if.exit6
|
||||
%val9 = phi i1 [ %17, %if.exit6 ], [ %20, %cond.rhs7 ]
|
||||
br i1 %val9, label %if.then10, label %if.exit11
|
||||
|
||||
if.then10: ; preds = %cond.phi8
|
||||
call void (ptr, ...) @printf(ptr @.str.2)
|
||||
br label %if.exit11
|
||||
|
||||
if.exit11: ; preds = %if.then10, %cond.phi8
|
||||
%21 = load i8, ptr %b, align 1
|
||||
br i1 %17, label %cond.lhs7, label %cond.rhs8
|
||||
cond.lhs7: ; preds = %if.exit6
|
||||
%18 = load i8, ptr %.anon, align 1
|
||||
%19 = trunc i8 %18 to i1
|
||||
br label %cond.phi9
|
||||
cond.rhs8: ; preds = %if.exit6
|
||||
%20 = load ptr, ptr %c, align 8
|
||||
%21 = load i8, ptr %20, align 1
|
||||
%22 = trunc i8 %21 to i1
|
||||
br i1 %22, label %cond.phi13, label %cond.rhs12
|
||||
|
||||
cond.rhs12: ; preds = %if.exit11
|
||||
br label %cond.phi9
|
||||
cond.phi9: ; preds = %cond.rhs8, %cond.lhs7
|
||||
%val10 = phi i1 [ %19, %cond.lhs7 ], [ %22, %cond.rhs8 ]
|
||||
br i1 %val10, label %if.then11, label %if.exit12
|
||||
if.then11: ; preds = %cond.phi9
|
||||
call void (ptr, ...) @printf(ptr @.str.2)
|
||||
br label %if.exit12
|
||||
if.exit12: ; preds = %if.then11, %cond.phi9
|
||||
%23 = load i8, ptr %b, align 1
|
||||
store i8 %23, ptr %.anon13, align 1
|
||||
%24 = trunc i8 %23 to i1
|
||||
br label %cond.phi13
|
||||
|
||||
cond.phi13: ; preds = %cond.rhs12, %if.exit11
|
||||
%val14 = phi i1 [ %22, %if.exit11 ], [ %24, %cond.rhs12 ]
|
||||
br i1 %val14, label %if.then15, label %if.exit16
|
||||
|
||||
if.then15: ; preds = %cond.phi13
|
||||
br i1 %24, label %cond.lhs14, label %cond.rhs15
|
||||
cond.lhs14: ; preds = %if.exit12
|
||||
%25 = load i8, ptr %.anon13, align 1
|
||||
%26 = trunc i8 %25 to i1
|
||||
br label %cond.phi16
|
||||
cond.rhs15: ; preds = %if.exit12
|
||||
%27 = load i8, ptr %b, align 1
|
||||
%28 = trunc i8 %27 to i1
|
||||
br label %cond.phi16
|
||||
cond.phi16: ; preds = %cond.rhs15, %cond.lhs14
|
||||
%val17 = phi i1 [ %26, %cond.lhs14 ], [ %28, %cond.rhs15 ]
|
||||
br i1 %val17, label %if.then18, label %if.exit19
|
||||
if.then18: ; preds = %cond.phi16
|
||||
call void (ptr, ...) @printf(ptr @.str.3)
|
||||
br label %if.exit16
|
||||
|
||||
if.exit16: ; preds = %if.then15, %cond.phi13
|
||||
br label %if.exit19
|
||||
if.exit19: ; preds = %if.then18, %cond.phi16
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ entry:
|
||||
%b = alloca i32, align 4
|
||||
%c = alloca i8, align 1
|
||||
%d = alloca i32, align 4
|
||||
%.anon = alloca i32, align 4
|
||||
store i8 1, ptr %a, align 1
|
||||
store i32 2, ptr %b, align 4
|
||||
%0 = load i32, ptr %b, align 4
|
||||
@@ -27,8 +28,19 @@ entry:
|
||||
%ternary = select i1 %siui-gt, i8 1, i8 0
|
||||
store i8 %ternary, ptr %c, align 1
|
||||
%2 = load i32, ptr %b, align 4
|
||||
%intbool = icmp ne i32 %2, 0
|
||||
%elvis = select i1 %intbool, i32 %2, i32 1
|
||||
store i32 %elvis, ptr %d, align 4
|
||||
store i32 %2, ptr %.anon, align 4
|
||||
%i2b = icmp ne i32 %2, 0
|
||||
br i1 %i2b, label %cond.lhs, label %cond.rhs
|
||||
|
||||
cond.lhs: ; preds = %entry
|
||||
%3 = load i32, ptr %.anon, align 4
|
||||
br label %cond.phi
|
||||
|
||||
cond.rhs: ; preds = %entry
|
||||
br label %cond.phi
|
||||
|
||||
cond.phi: ; preds = %cond.rhs, %cond.lhs
|
||||
%val = phi i32 [ %3, %cond.lhs ], [ 1, %cond.rhs ]
|
||||
store i32 %val, ptr %d, align 4
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user