[Mlir-commits] [mlir] [mlir][spirv] Add folding for SNegate, [Logical]Not (PR #74992)
Jakub Kuderski
llvmlistbot at llvm.org
Wed Dec 20 20:18:48 PST 2023
================
@@ -643,6 +643,45 @@ OpFoldResult spirv::UModOp::fold(FoldAdaptor adaptor) {
return div0 ? Attribute() : res;
}
+//===----------------------------------------------------------------------===//
+// spirv.SNegate
+//===----------------------------------------------------------------------===//
+
+OpFoldResult spirv::SNegateOp::fold(FoldAdaptor adaptor) {
+ // -(-x) = 0 - (0 - x) = x
+ auto op = getOperand();
+ if (auto negateOp = op.getDefiningOp<spirv::SNegateOp>())
+ return negateOp->getOperand(0);
----------------
kuhar wrote:
I wasn't sure if this works for INT_MIN, it should check out like that:
- `- INT_MIN == INT_MIN`
- `- (- INT_MIN) == - INT_MIN = INT_MIN`
which looks fine
https://github.com/llvm/llvm-project/pull/74992
More information about the Mlir-commits
mailing list