-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds a new `cir.select` operation. This operation won't be generated directly by CIRGen but it is useful during further CIR to CIR transformations. This patch addresses #785 .
- Loading branch information
Showing
7 changed files
with
232 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// RUN: cir-translate -cir-to-llvmir -o %t.ll %s | ||
// RUN: FileCheck --input-file=%t.ll -check-prefix=LLVM %s | ||
|
||
!s32i = !cir.int<s, 32> | ||
|
||
module { | ||
cir.func @select_int(%arg0 : !cir.bool, %arg1 : !s32i, %arg2 : !s32i) -> !s32i { | ||
%0 = cir.select if %arg0 then %arg1 else %arg2 : (!cir.bool, !s32i, !s32i) -> !s32i | ||
cir.return %0 : !s32i | ||
} | ||
|
||
// LLVM: define i32 @select_int(i8 %[[#COND:]], i32 %[[#TV:]], i32 %[[#FV:]]) | ||
// LLVM-NEXT: %[[#CONDF:]] = trunc i8 %[[#COND]] to i1 | ||
// LLVM-NEXT: %[[#RES:]] = select i1 %[[#CONDF]], i32 %[[#TV]], i32 %[[#FV]] | ||
// LLVM-NEXT: ret i32 %[[#RES]] | ||
// LLVM-NEXT: } | ||
|
||
cir.func @select_bool(%arg0 : !cir.bool, %arg1 : !cir.bool, %arg2 : !cir.bool) -> !cir.bool { | ||
%0 = cir.select if %arg0 then %arg1 else %arg2 : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool | ||
cir.return %0 : !cir.bool | ||
} | ||
|
||
// LLVM: define i8 @select_bool(i8 %[[#COND:]], i8 %[[#TV:]], i8 %[[#FV:]]) | ||
// LLVM-NEXT: %[[#CONDF:]] = trunc i8 %[[#COND]] to i1 | ||
// LLVM-NEXT: %[[#RES:]] = select i1 %[[#CONDF]], i8 %[[#TV]], i8 %[[#FV]] | ||
// LLVM-NEXT: ret i8 %[[#RES]] | ||
// LLVM-NEXT: } | ||
|
||
cir.func @logical_and(%arg0 : !cir.bool, %arg1 : !cir.bool) -> !cir.bool { | ||
%0 = cir.const #cir.bool<false> : !cir.bool | ||
%1 = cir.select if %arg0 then %arg1 else %0 : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool | ||
cir.return %1 : !cir.bool | ||
} | ||
|
||
// LLVM: define i8 @logical_and(i8 %[[#ARG0:]], i8 %[[#ARG1:]]) | ||
// LLVM-NEXT: %[[#RES:]] = and i8 %[[#ARG0]], %[[#ARG1]] | ||
// LLVM-NEXT: ret i8 %[[#RES]] | ||
// LLVM-NEXT: } | ||
|
||
cir.func @logical_or(%arg0 : !cir.bool, %arg1 : !cir.bool) -> !cir.bool { | ||
%0 = cir.const #cir.bool<true> : !cir.bool | ||
%1 = cir.select if %arg0 then %0 else %arg1 : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool | ||
cir.return %1 : !cir.bool | ||
} | ||
|
||
// LLVM: define i8 @logical_or(i8 %[[#ARG0:]], i8 %[[#ARG1:]]) | ||
// LLVM-NEXT: %[[#RES:]] = or i8 %[[#ARG0]], %[[#ARG1]] | ||
// LLVM-NEXT: ret i8 %[[#RES]] | ||
// LLVM-NEXT: } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// RUN: cir-opt --canonicalize -o %t.cir %s | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
!s32i = !cir.int<s, 32> | ||
|
||
module { | ||
cir.func @fold_true(%arg0 : !s32i, %arg1 : !s32i) -> !s32i { | ||
%0 = cir.const #cir.bool<true> : !cir.bool | ||
%1 = cir.select if %0 then %arg0 else %arg1 : (!cir.bool, !s32i, !s32i) -> !s32i | ||
cir.return %1 : !s32i | ||
} | ||
|
||
// CHECK: cir.func @fold_true(%[[ARG0:.+]]: !s32i, %[[ARG1:.+]]: !s32i) -> !s32i { | ||
// CHECK-NEXT: cir.return %[[ARG0]] : !s32i | ||
// CHECK-NEXT: } | ||
|
||
cir.func @fold_false(%arg0 : !s32i, %arg1 : !s32i) -> !s32i { | ||
%0 = cir.const #cir.bool<false> : !cir.bool | ||
%1 = cir.select if %0 then %arg0 else %arg1 : (!cir.bool, !s32i, !s32i) -> !s32i | ||
cir.return %1 : !s32i | ||
} | ||
|
||
// CHECK: cir.func @fold_false(%[[ARG0:.+]]: !s32i, %[[ARG1:.+]]: !s32i) -> !s32i { | ||
// CHECK-NEXT: cir.return %[[ARG1]] : !s32i | ||
// CHECK-NEXT: } | ||
} |