@@ -28,7 +28,7 @@ def MulIntAttrs : NativeCodeCall<"mulIntegerAttrs($_builder, $0, $1, $2)">;
28
28
// flags and always reset them to default (wraparound) which is safe but can
29
29
// inhibit later optimizations. Individual patterns must be reviewed for
30
30
// better handling of overflow flags.
31
- def DefOverflow : NativeCodeCall<"getDefOverflowFlags($_builder) ">;
31
+ defvar DefOverflow = ConstantEnumCase<Arith_IntegerOverflowAttr, "none ">;
32
32
33
33
class cast<string type> : NativeCodeCall<"::mlir::cast<" # type # ">($0)">;
34
34
@@ -45,23 +45,23 @@ def AddIAddConstant :
45
45
(Arith_AddIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
46
46
(ConstantLikeMatcher APIntAttr:$c1), $ovf2),
47
47
(Arith_AddIOp $x, (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)),
48
- ( DefOverflow) )>;
48
+ DefOverflow)>;
49
49
50
50
// addi(subi(x, c0), c1) -> addi(x, c1 - c0)
51
51
def AddISubConstantRHS :
52
52
Pat<(Arith_AddIOp:$res
53
53
(Arith_SubIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
54
54
(ConstantLikeMatcher APIntAttr:$c1), $ovf2),
55
55
(Arith_AddIOp $x, (Arith_ConstantOp (SubIntAttrs $res, $c1, $c0)),
56
- ( DefOverflow) )>;
56
+ DefOverflow)>;
57
57
58
58
// addi(subi(c0, x), c1) -> subi(c0 + c1, x)
59
59
def AddISubConstantLHS :
60
60
Pat<(Arith_AddIOp:$res
61
61
(Arith_SubIOp (ConstantLikeMatcher APIntAttr:$c0), $x, $ovf1),
62
62
(ConstantLikeMatcher APIntAttr:$c1), $ovf2),
63
63
(Arith_SubIOp (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)), $x,
64
- ( DefOverflow) )>;
64
+ DefOverflow)>;
65
65
66
66
def IsScalarOrSplatNegativeOne :
67
67
Constraint<And<[
@@ -73,15 +73,15 @@ def AddIMulNegativeOneRhs :
73
73
Pat<(Arith_AddIOp
74
74
$x,
75
75
(Arith_MulIOp $y, (ConstantLikeMatcher AnyAttr:$c0), $ovf1), $ovf2),
76
- (Arith_SubIOp $x, $y, ( DefOverflow) ),
76
+ (Arith_SubIOp $x, $y, DefOverflow),
77
77
[(IsScalarOrSplatNegativeOne $c0)]>;
78
78
79
79
// addi(muli(x, -1), y) -> subi(y, x)
80
80
def AddIMulNegativeOneLhs :
81
81
Pat<(Arith_AddIOp
82
82
(Arith_MulIOp $x, (ConstantLikeMatcher AnyAttr:$c0), $ovf1),
83
83
$y, $ovf2),
84
- (Arith_SubIOp $y, $x, ( DefOverflow) ),
84
+ (Arith_SubIOp $y, $x, DefOverflow),
85
85
[(IsScalarOrSplatNegativeOne $c0)]>;
86
86
87
87
// muli(muli(x, c0), c1) -> muli(x, c0 * c1)
@@ -90,7 +90,7 @@ def MulIMulIConstant :
90
90
(Arith_MulIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
91
91
(ConstantLikeMatcher APIntAttr:$c1), $ovf2),
92
92
(Arith_MulIOp $x, (Arith_ConstantOp (MulIntAttrs $res, $c0, $c1)),
93
- ( DefOverflow) )>;
93
+ DefOverflow)>;
94
94
95
95
//===----------------------------------------------------------------------===//
96
96
// AddUIExtendedOp
@@ -100,7 +100,7 @@ def MulIMulIConstant :
100
100
// uses. Since the 'overflow' result is unused, any replacement value will do.
101
101
def AddUIExtendedToAddI:
102
102
Pattern<(Arith_AddUIExtendedOp:$res $x, $y),
103
- [(Arith_AddIOp $x, $y, ( DefOverflow) ), (replaceWithValue $x)],
103
+ [(Arith_AddIOp $x, $y, DefOverflow), (replaceWithValue $x)],
104
104
[(Constraint<CPred<"$0.getUses().empty()">> $res__1)]>;
105
105
106
106
//===----------------------------------------------------------------------===//
@@ -113,52 +113,52 @@ def SubIRHSAddConstant :
113
113
(Arith_AddIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
114
114
(ConstantLikeMatcher APIntAttr:$c1), $ovf2),
115
115
(Arith_AddIOp $x, (Arith_ConstantOp (SubIntAttrs $res, $c0, $c1)),
116
- ( DefOverflow) )>;
116
+ DefOverflow)>;
117
117
118
118
// subi(c1, addi(x, c0)) -> subi(c1 - c0, x)
119
119
def SubILHSAddConstant :
120
120
Pat<(Arith_SubIOp:$res
121
121
(ConstantLikeMatcher APIntAttr:$c1),
122
122
(Arith_AddIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1), $ovf2),
123
123
(Arith_SubIOp (Arith_ConstantOp (SubIntAttrs $res, $c1, $c0)), $x,
124
- ( DefOverflow) )>;
124
+ DefOverflow)>;
125
125
126
126
// subi(subi(x, c0), c1) -> subi(x, c0 + c1)
127
127
def SubIRHSSubConstantRHS :
128
128
Pat<(Arith_SubIOp:$res
129
129
(Arith_SubIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
130
130
(ConstantLikeMatcher APIntAttr:$c1), $ovf2),
131
131
(Arith_SubIOp $x, (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)),
132
- ( DefOverflow) )>;
132
+ DefOverflow)>;
133
133
134
134
// subi(subi(c0, x), c1) -> subi(c0 - c1, x)
135
135
def SubIRHSSubConstantLHS :
136
136
Pat<(Arith_SubIOp:$res
137
137
(Arith_SubIOp (ConstantLikeMatcher APIntAttr:$c0), $x, $ovf1),
138
138
(ConstantLikeMatcher APIntAttr:$c1), $ovf2),
139
139
(Arith_SubIOp (Arith_ConstantOp (SubIntAttrs $res, $c0, $c1)), $x,
140
- ( DefOverflow) )>;
140
+ DefOverflow)>;
141
141
142
142
// subi(c1, subi(x, c0)) -> subi(c0 + c1, x)
143
143
def SubILHSSubConstantRHS :
144
144
Pat<(Arith_SubIOp:$res
145
145
(ConstantLikeMatcher APIntAttr:$c1),
146
146
(Arith_SubIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1), $ovf2),
147
147
(Arith_SubIOp (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)), $x,
148
- ( DefOverflow) )>;
148
+ DefOverflow)>;
149
149
150
150
// subi(c1, subi(c0, x)) -> addi(x, c1 - c0)
151
151
def SubILHSSubConstantLHS :
152
152
Pat<(Arith_SubIOp:$res
153
153
(ConstantLikeMatcher APIntAttr:$c1),
154
154
(Arith_SubIOp (ConstantLikeMatcher APIntAttr:$c0), $x, $ovf1), $ovf2),
155
155
(Arith_AddIOp $x, (Arith_ConstantOp (SubIntAttrs $res, $c1, $c0)),
156
- ( DefOverflow) )>;
156
+ DefOverflow)>;
157
157
158
158
// subi(subi(a, b), a) -> subi(0, b)
159
159
def SubISubILHSRHSLHS :
160
160
Pat<(Arith_SubIOp:$res (Arith_SubIOp $x, $y, $ovf1), $x, $ovf2),
161
- (Arith_SubIOp (Arith_ConstantOp (GetZeroAttr $y)), $y, ( DefOverflow) )>;
161
+ (Arith_SubIOp (Arith_ConstantOp (GetZeroAttr $y)), $y, DefOverflow)>;
162
162
163
163
//===----------------------------------------------------------------------===//
164
164
// MulSIExtendedOp
@@ -168,7 +168,7 @@ def SubISubILHSRHSLHS :
168
168
// Since the `high` result it not used, any replacement value will do.
169
169
def MulSIExtendedToMulI :
170
170
Pattern<(Arith_MulSIExtendedOp:$res $x, $y),
171
- [(Arith_MulIOp $x, $y, ( DefOverflow) ), (replaceWithValue $x)],
171
+ [(Arith_MulIOp $x, $y, DefOverflow), (replaceWithValue $x)],
172
172
[(Constraint<CPred<"$0.getUses().empty()">> $res__1)]>;
173
173
174
174
@@ -182,9 +182,9 @@ def MulSIExtendedRHSOne :
182
182
Pattern<(Arith_MulSIExtendedOp $x, (ConstantLikeMatcher AnyAttr:$c1)),
183
183
[(replaceWithValue $x),
184
184
(Arith_ExtSIOp(Arith_CmpIOp
185
- (NativeCodeCall<"arith::CmpIPredicate:: slt">) ,
186
- $x,
187
- (Arith_ConstantOp (GetZeroAttr $x))))],
185
+ ConstantEnumCase<Arith_CmpIPredicateAttr, " slt">,
186
+ $x,
187
+ (Arith_ConstantOp (GetZeroAttr $x))))],
188
188
[(IsScalarOrSplatOne $c1)]>;
189
189
190
190
//===----------------------------------------------------------------------===//
@@ -195,7 +195,7 @@ def MulSIExtendedRHSOne :
195
195
// Since the `high` result it not used, any replacement value will do.
196
196
def MulUIExtendedToMulI :
197
197
Pattern<(Arith_MulUIExtendedOp:$res $x, $y),
198
- [(Arith_MulIOp $x, $y, ( DefOverflow) ), (replaceWithValue $x)],
198
+ [(Arith_MulIOp $x, $y, DefOverflow), (replaceWithValue $x)],
199
199
[(Constraint<CPred<"$0.getUses().empty()">> $res__1)]>;
200
200
201
201
//===----------------------------------------------------------------------===//
0 commit comments