File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed
include/mlir/Dialect/Arithmetic/IR
lib/Dialect/Arithmetic/IR Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -818,6 +818,7 @@ def Arith_ExtSIOp : Arith_IToICastOp<"extsi"> {
818
818
}];
819
819
820
820
let hasFolder = 1;
821
+ let hasCanonicalizer = 1;
821
822
let verifier = [{ return verifyExtOp<IntegerType>(*this); }];
822
823
}
823
824
Original file line number Diff line number Diff line change @@ -128,4 +128,12 @@ def IndexCastOfExtSI :
128
128
def BitcastOfBitcast :
129
129
Pat<(Arith_BitcastOp (Arith_BitcastOp $x)), (replaceWithValue $x)>;
130
130
131
+ //===----------------------------------------------------------------------===//
132
+ // ExtSIOp
133
+ //===----------------------------------------------------------------------===//
134
+
135
+ // extsi(extui(x iN : iM) : iL) -> extui(x : iL)
136
+ def ExtSIOfExtUI :
137
+ Pat<(Arith_ExtSIOp (Arith_ExtUIOp $x)), (Arith_ExtUIOp $x)>;
138
+
131
139
#endif // ARITHMETIC_PATTERNS
Original file line number Diff line number Diff line change @@ -788,6 +788,11 @@ OpFoldResult arith::ExtUIOp::fold(ArrayRef<Attribute> operands) {
788
788
return IntegerAttr::get (
789
789
getType (), lhs.getValue ().zext (getType ().getIntOrFloatBitWidth ()));
790
790
791
+ if (auto lhs = getIn ().getDefiningOp <ExtUIOp>()) {
792
+ getInMutable ().assign (lhs.getIn ());
793
+ return getResult ();
794
+ }
795
+
791
796
return {};
792
797
}
793
798
@@ -804,13 +809,23 @@ OpFoldResult arith::ExtSIOp::fold(ArrayRef<Attribute> operands) {
804
809
return IntegerAttr::get (
805
810
getType (), lhs.getValue ().sext (getType ().getIntOrFloatBitWidth ()));
806
811
812
+ if (auto lhs = getIn ().getDefiningOp <ExtSIOp>()) {
813
+ getInMutable ().assign (lhs.getIn ());
814
+ return getResult ();
815
+ }
816
+
807
817
return {};
808
818
}
809
819
810
820
bool arith::ExtSIOp::areCastCompatible (TypeRange inputs, TypeRange outputs) {
811
821
return checkWidthChangeCast<std::greater, IntegerType>(inputs, outputs);
812
822
}
813
823
824
+ void arith::ExtSIOp::getCanonicalizationPatterns (
825
+ OwningRewritePatternList &patterns, MLIRContext *context) {
826
+ patterns.insert <ExtSIOfExtUI>(context);
827
+ }
828
+
814
829
// ===----------------------------------------------------------------------===//
815
830
// ExtFOp
816
831
// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -70,6 +70,35 @@ func @cmpOfExtUI(%arg0: i1) -> i1 {
70
70
71
71
// -----
72
72
73
+ // CHECK-LABEL: @extSIOfExtUI
74
+ // CHECK: %[[res:.+]] = arith.extui %arg0 : i1 to i64
75
+ // CHECK: return %[[res]]
76
+ func @extSIOfExtUI (%arg0: i1 ) -> i64 {
77
+ %ext1 = arith.extui %arg0 : i1 to i8
78
+ %ext2 = arith.extsi %ext1 : i8 to i64
79
+ return %ext2 : i64
80
+ }
81
+
82
+ // CHECK-LABEL: @extUIOfExtUI
83
+ // CHECK: %[[res:.+]] = arith.extui %arg0 : i1 to i64
84
+ // CHECK: return %[[res]]
85
+ func @extUIOfExtUI (%arg0: i1 ) -> i64 {
86
+ %ext1 = arith.extui %arg0 : i1 to i8
87
+ %ext2 = arith.extui %ext1 : i8 to i64
88
+ return %ext2 : i64
89
+ }
90
+
91
+ // CHECK-LABEL: @extSIOfExtSI
92
+ // CHECK: %[[res:.+]] = arith.extsi %arg0 : i1 to i64
93
+ // CHECK: return %[[res]]
94
+ func @extSIOfExtSI (%arg0: i1 ) -> i64 {
95
+ %ext1 = arith.extsi %arg0 : i1 to i8
96
+ %ext2 = arith.extsi %ext1 : i8 to i64
97
+ return %ext2 : i64
98
+ }
99
+
100
+ // -----
101
+
73
102
// CHECK-LABEL: @indexCastOfSignExtend
74
103
// CHECK: %[[res:.+]] = arith.index_cast %arg0 : i8 to index
75
104
// CHECK: return %[[res]]
You can’t perform that action at this time.
0 commit comments