forked from OSchip/llvm-project
[MLIR] Create folders for extsi/extui
Create folders/canonicalizers for extsi/extui. Specifically, extui(extui(x)) -> extui(x) extsi(extsi(x)) -> extsi(x) extsi(extui(x)) -> extui(x) Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D116515
This commit is contained in:
parent
89af17c0c7
commit
1bb9f4e482
|
@ -818,6 +818,7 @@ def Arith_ExtSIOp : Arith_IToICastOp<"extsi"> {
|
|||
}];
|
||||
|
||||
let hasFolder = 1;
|
||||
let hasCanonicalizer = 1;
|
||||
let verifier = [{ return verifyExtOp<IntegerType>(*this); }];
|
||||
}
|
||||
|
||||
|
|
|
@ -128,4 +128,12 @@ def IndexCastOfExtSI :
|
|||
def BitcastOfBitcast :
|
||||
Pat<(Arith_BitcastOp (Arith_BitcastOp $x)), (replaceWithValue $x)>;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ExtSIOp
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// extsi(extui(x iN : iM) : iL) -> extui(x : iL)
|
||||
def ExtSIOfExtUI :
|
||||
Pat<(Arith_ExtSIOp (Arith_ExtUIOp $x)), (Arith_ExtUIOp $x)>;
|
||||
|
||||
#endif // ARITHMETIC_PATTERNS
|
||||
|
|
|
@ -788,6 +788,11 @@ OpFoldResult arith::ExtUIOp::fold(ArrayRef<Attribute> operands) {
|
|||
return IntegerAttr::get(
|
||||
getType(), lhs.getValue().zext(getType().getIntOrFloatBitWidth()));
|
||||
|
||||
if (auto lhs = getIn().getDefiningOp<ExtUIOp>()) {
|
||||
getInMutable().assign(lhs.getIn());
|
||||
return getResult();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -804,6 +809,11 @@ OpFoldResult arith::ExtSIOp::fold(ArrayRef<Attribute> operands) {
|
|||
return IntegerAttr::get(
|
||||
getType(), lhs.getValue().sext(getType().getIntOrFloatBitWidth()));
|
||||
|
||||
if (auto lhs = getIn().getDefiningOp<ExtSIOp>()) {
|
||||
getInMutable().assign(lhs.getIn());
|
||||
return getResult();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -811,6 +821,11 @@ bool arith::ExtSIOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
|
|||
return checkWidthChangeCast<std::greater, IntegerType>(inputs, outputs);
|
||||
}
|
||||
|
||||
void arith::ExtSIOp::getCanonicalizationPatterns(
|
||||
OwningRewritePatternList &patterns, MLIRContext *context) {
|
||||
patterns.insert<ExtSIOfExtUI>(context);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ExtFOp
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -70,6 +70,35 @@ func @cmpOfExtUI(%arg0: i1) -> i1 {
|
|||
|
||||
// -----
|
||||
|
||||
// CHECK-LABEL: @extSIOfExtUI
|
||||
// CHECK: %[[res:.+]] = arith.extui %arg0 : i1 to i64
|
||||
// CHECK: return %[[res]]
|
||||
func @extSIOfExtUI(%arg0: i1) -> i64 {
|
||||
%ext1 = arith.extui %arg0 : i1 to i8
|
||||
%ext2 = arith.extsi %ext1 : i8 to i64
|
||||
return %ext2 : i64
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @extUIOfExtUI
|
||||
// CHECK: %[[res:.+]] = arith.extui %arg0 : i1 to i64
|
||||
// CHECK: return %[[res]]
|
||||
func @extUIOfExtUI(%arg0: i1) -> i64 {
|
||||
%ext1 = arith.extui %arg0 : i1 to i8
|
||||
%ext2 = arith.extui %ext1 : i8 to i64
|
||||
return %ext2 : i64
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @extSIOfExtSI
|
||||
// CHECK: %[[res:.+]] = arith.extsi %arg0 : i1 to i64
|
||||
// CHECK: return %[[res]]
|
||||
func @extSIOfExtSI(%arg0: i1) -> i64 {
|
||||
%ext1 = arith.extsi %arg0 : i1 to i8
|
||||
%ext2 = arith.extsi %ext1 : i8 to i64
|
||||
return %ext2 : i64
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// CHECK-LABEL: @indexCastOfSignExtend
|
||||
// CHECK: %[[res:.+]] = arith.index_cast %arg0 : i8 to index
|
||||
// CHECK: return %[[res]]
|
||||
|
|
Loading…
Reference in New Issue