[Mlir-commits] [mlir] 28858d5 - [mlir][arith][NFC] Add missing index_cast fold tests

Jakub Kuderski llvmlistbot at llvm.org
Wed Mar 29 07:45:02 PDT 2023


Author: Jakub Kuderski
Date: 2023-03-29T10:40:12-04:00
New Revision: 28858d5902f84ab760c8531061d43539e2135ae1

URL: https://github.com/llvm/llvm-project/commit/28858d5902f84ab760c8531061d43539e2135ae1
DIFF: https://github.com/llvm/llvm-project/commit/28858d5902f84ab760c8531061d43539e2135ae1.diff

LOG: [mlir][arith][NFC] Add missing index_cast fold tests

It wasn't immediately obvious to me if index-to-integer casts were
folded or not.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D147104

Added: 
    

Modified: 
    mlir/test/Dialect/Arith/canonicalize.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/test/Dialect/Arith/canonicalize.mlir b/mlir/test/Dialect/Arith/canonicalize.mlir
index 396f5ee3dc6ea..b75dfd70e0508 100644
--- a/mlir/test/Dialect/Arith/canonicalize.mlir
+++ b/mlir/test/Dialect/Arith/canonicalize.mlir
@@ -431,21 +431,39 @@ func.func @indexCastUIOfUnsignedExtend(%arg0: i8) -> index {
 // CHECK-LABEL: @indexCastFold
 //       CHECK:   %[[res:.*]] = arith.constant -2 : index
 //       CHECK:   return %[[res]]
-func.func @indexCastFold(%arg0: i8) -> index {
+func.func @indexCastFold() -> index {
   %c-2 = arith.constant -2 : i8
   %idx = arith.index_cast %c-2 : i8 to index
   return %idx : index
 }
 
+// CHECK-LABEL: @indexCastFoldIndexToInt
+//       CHECK:   %[[res:.*]] = arith.constant 1 : i32
+//       CHECK:   return %[[res]]
+func.func @indexCastFoldIndexToInt() -> i32 {
+  %c1 = arith.constant 1 : index
+  %int = arith.index_cast %c1 : index to i32
+  return %int : i32
+}
+
 // CHECK-LABEL: @indexCastUIFold
 //       CHECK:   %[[res:.*]] = arith.constant 254 : index
 //       CHECK:   return %[[res]]
-func.func @indexCastUIFold(%arg0: i8) -> index {
+func.func @indexCastUIFold() -> index {
   %c-2 = arith.constant -2 : i8
   %idx = arith.index_castui %c-2 : i8 to index
   return %idx : index
 }
 
+// CHECK-LABEL: @indexCastUIFoldIndexToInt
+//       CHECK:   %[[res:.*]] = arith.constant 1 : i32
+//       CHECK:   return %[[res]]
+func.func @indexCastUIFoldIndexToInt() -> i32 {
+  %c1 = arith.constant 1 : index
+  %int = arith.index_castui %c1 : index to i32
+  return %int : i32
+}
+
 // CHECK-LABEL: @signExtendConstant
 //       CHECK:   %[[cres:.+]] = arith.constant -2 : i16
 //       CHECK:   return %[[cres]]


        


More information about the Mlir-commits mailing list