-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR][CodeGen] Integer lowering of unary plus and minus
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// RUN: cir-tool %s -cir-to-func -cir-to-memref -o - | FileCheck %s -check-prefix=MLIR | ||
// RUN: cir-tool %s -cir-to-func -cir-to-memref -cir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM | ||
|
||
module { | ||
cir.func @foo() { | ||
%0 = cir.alloca i32, cir.ptr <i32>, ["a", init] {alignment = 4 : i64} | ||
%1 = cir.alloca i32, cir.ptr <i32>, ["b", init] {alignment = 4 : i64} | ||
%2 = cir.cst(2 : i32) : i32 | ||
cir.store %2, %0 : i32, cir.ptr <i32> | ||
cir.store %2, %1 : i32, cir.ptr <i32> | ||
|
||
%3 = cir.load %0 : cir.ptr <i32>, i32 | ||
%4 = cir.unary(plus, %3) : i32, i32 | ||
cir.store %4, %0 : i32, cir.ptr <i32> | ||
|
||
%5 = cir.load %1 : cir.ptr <i32>, i32 | ||
%6 = cir.unary(minus, %5) : i32, i32 | ||
cir.store %6, %1 : i32, cir.ptr <i32> | ||
cir.return | ||
} | ||
} | ||
|
||
// MLIR: %[[#INPUT_PLUS:]] = memref.load | ||
// MLIR: memref.store %[[#INPUT_PLUS]] | ||
// MLIR: %[[#INPUT_MINUS:]] = memref.load | ||
// MLIR: %[[ZERO:[a-z0-9_]+]] = arith.constant 0 | ||
// MLIR: arith.subi %[[ZERO]], %[[#INPUT_MINUS]] | ||
|
||
// LLVM: = sub i32 0, %[[#]] |