@@ -28,7 +28,7 @@ def MulIntAttrs : NativeCodeCall<"mulIntegerAttrs($_builder, $0, $1, $2)">;
2828// flags and always reset them to default (wraparound) which is safe but can
2929// inhibit later optimizations. Individual patterns must be reviewed for
3030// better handling of overflow flags.
31- def DefOverflow : NativeCodeCall<"getDefOverflowFlags($_builder) ">;
31+ defvar DefOverflow = ConstantEnumCase<Arith_IntegerOverflowAttr, "none ">;
3232
3333class cast<string type> : NativeCodeCall<"::mlir::cast<" # type # ">($0)">;
3434
@@ -45,23 +45,23 @@ def AddIAddConstant :
4545 (Arith_AddIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
4646 (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
4747 (Arith_AddIOp $x, (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)),
48- ( DefOverflow) )>;
48+ DefOverflow)>;
4949
5050// addi(subi(x, c0), c1) -> addi(x, c1 - c0)
5151def AddISubConstantRHS :
5252 Pat<(Arith_AddIOp:$res
5353 (Arith_SubIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
5454 (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
5555 (Arith_AddIOp $x, (Arith_ConstantOp (SubIntAttrs $res, $c1, $c0)),
56- ( DefOverflow) )>;
56+ DefOverflow)>;
5757
5858// addi(subi(c0, x), c1) -> subi(c0 + c1, x)
5959def AddISubConstantLHS :
6060 Pat<(Arith_AddIOp:$res
6161 (Arith_SubIOp (ConstantLikeMatcher APIntAttr:$c0), $x, $ovf1),
6262 (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
6363 (Arith_SubIOp (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)), $x,
64- ( DefOverflow) )>;
64+ DefOverflow)>;
6565
6666def IsScalarOrSplatNegativeOne :
6767 Constraint<And<[
@@ -73,15 +73,15 @@ def AddIMulNegativeOneRhs :
7373 Pat<(Arith_AddIOp
7474 $x,
7575 (Arith_MulIOp $y, (ConstantLikeMatcher AnyAttr:$c0), $ovf1), $ovf2),
76- (Arith_SubIOp $x, $y, ( DefOverflow) ),
76+ (Arith_SubIOp $x, $y, DefOverflow),
7777 [(IsScalarOrSplatNegativeOne $c0)]>;
7878
7979// addi(muli(x, -1), y) -> subi(y, x)
8080def AddIMulNegativeOneLhs :
8181 Pat<(Arith_AddIOp
8282 (Arith_MulIOp $x, (ConstantLikeMatcher AnyAttr:$c0), $ovf1),
8383 $y, $ovf2),
84- (Arith_SubIOp $y, $x, ( DefOverflow) ),
84+ (Arith_SubIOp $y, $x, DefOverflow),
8585 [(IsScalarOrSplatNegativeOne $c0)]>;
8686
8787// muli(muli(x, c0), c1) -> muli(x, c0 * c1)
@@ -90,7 +90,7 @@ def MulIMulIConstant :
9090 (Arith_MulIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
9191 (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
9292 (Arith_MulIOp $x, (Arith_ConstantOp (MulIntAttrs $res, $c0, $c1)),
93- ( DefOverflow) )>;
93+ DefOverflow)>;
9494
9595//===----------------------------------------------------------------------===//
9696// AddUIExtendedOp
@@ -100,7 +100,7 @@ def MulIMulIConstant :
100100// uses. Since the 'overflow' result is unused, any replacement value will do.
101101def AddUIExtendedToAddI:
102102 Pattern<(Arith_AddUIExtendedOp:$res $x, $y),
103- [(Arith_AddIOp $x, $y, ( DefOverflow) ), (replaceWithValue $x)],
103+ [(Arith_AddIOp $x, $y, DefOverflow), (replaceWithValue $x)],
104104 [(Constraint<CPred<"$0.getUses().empty()">> $res__1)]>;
105105
106106//===----------------------------------------------------------------------===//
@@ -113,52 +113,52 @@ def SubIRHSAddConstant :
113113 (Arith_AddIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
114114 (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
115115 (Arith_AddIOp $x, (Arith_ConstantOp (SubIntAttrs $res, $c0, $c1)),
116- ( DefOverflow) )>;
116+ DefOverflow)>;
117117
118118// subi(c1, addi(x, c0)) -> subi(c1 - c0, x)
119119def SubILHSAddConstant :
120120 Pat<(Arith_SubIOp:$res
121121 (ConstantLikeMatcher APIntAttr:$c1),
122122 (Arith_AddIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1), $ovf2),
123123 (Arith_SubIOp (Arith_ConstantOp (SubIntAttrs $res, $c1, $c0)), $x,
124- ( DefOverflow) )>;
124+ DefOverflow)>;
125125
126126// subi(subi(x, c0), c1) -> subi(x, c0 + c1)
127127def SubIRHSSubConstantRHS :
128128 Pat<(Arith_SubIOp:$res
129129 (Arith_SubIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
130130 (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
131131 (Arith_SubIOp $x, (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)),
132- ( DefOverflow) )>;
132+ DefOverflow)>;
133133
134134// subi(subi(c0, x), c1) -> subi(c0 - c1, x)
135135def SubIRHSSubConstantLHS :
136136 Pat<(Arith_SubIOp:$res
137137 (Arith_SubIOp (ConstantLikeMatcher APIntAttr:$c0), $x, $ovf1),
138138 (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
139139 (Arith_SubIOp (Arith_ConstantOp (SubIntAttrs $res, $c0, $c1)), $x,
140- ( DefOverflow) )>;
140+ DefOverflow)>;
141141
142142// subi(c1, subi(x, c0)) -> subi(c0 + c1, x)
143143def SubILHSSubConstantRHS :
144144 Pat<(Arith_SubIOp:$res
145145 (ConstantLikeMatcher APIntAttr:$c1),
146146 (Arith_SubIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1), $ovf2),
147147 (Arith_SubIOp (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)), $x,
148- ( DefOverflow) )>;
148+ DefOverflow)>;
149149
150150// subi(c1, subi(c0, x)) -> addi(x, c1 - c0)
151151def SubILHSSubConstantLHS :
152152 Pat<(Arith_SubIOp:$res
153153 (ConstantLikeMatcher APIntAttr:$c1),
154154 (Arith_SubIOp (ConstantLikeMatcher APIntAttr:$c0), $x, $ovf1), $ovf2),
155155 (Arith_AddIOp $x, (Arith_ConstantOp (SubIntAttrs $res, $c1, $c0)),
156- ( DefOverflow) )>;
156+ DefOverflow)>;
157157
158158// subi(subi(a, b), a) -> subi(0, b)
159159def SubISubILHSRHSLHS :
160160 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)>;
162162
163163//===----------------------------------------------------------------------===//
164164// MulSIExtendedOp
@@ -168,7 +168,7 @@ def SubISubILHSRHSLHS :
168168// Since the `high` result it not used, any replacement value will do.
169169def MulSIExtendedToMulI :
170170 Pattern<(Arith_MulSIExtendedOp:$res $x, $y),
171- [(Arith_MulIOp $x, $y, ( DefOverflow) ), (replaceWithValue $x)],
171+ [(Arith_MulIOp $x, $y, DefOverflow), (replaceWithValue $x)],
172172 [(Constraint<CPred<"$0.getUses().empty()">> $res__1)]>;
173173
174174
@@ -182,9 +182,9 @@ def MulSIExtendedRHSOne :
182182 Pattern<(Arith_MulSIExtendedOp $x, (ConstantLikeMatcher AnyAttr:$c1)),
183183 [(replaceWithValue $x),
184184 (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))))],
188188 [(IsScalarOrSplatOne $c1)]>;
189189
190190//===----------------------------------------------------------------------===//
@@ -195,7 +195,7 @@ def MulSIExtendedRHSOne :
195195// Since the `high` result it not used, any replacement value will do.
196196def MulUIExtendedToMulI :
197197 Pattern<(Arith_MulUIExtendedOp:$res $x, $y),
198- [(Arith_MulIOp $x, $y, ( DefOverflow) ), (replaceWithValue $x)],
198+ [(Arith_MulIOp $x, $y, DefOverflow), (replaceWithValue $x)],
199199 [(Constraint<CPred<"$0.getUses().empty()">> $res__1)]>;
200200
201201//===----------------------------------------------------------------------===//
0 commit comments