[Mlir-commits] [mlir] [mlir][emitc] Only mark operator with fundamental type have no side effect (PR #144990)

Gil Rapaport llvmlistbot at llvm.org
Tue Jul 29 08:33:10 PDT 2025


================
@@ -57,7 +61,18 @@ class EmitC_BinaryOp<string mnemonic, list<Trait> traits = []> :
 
   let extraClassDeclaration = [{
     bool hasSideEffects() {
-      return false;
+      // If both operands are fundamental types, the operation is pure.
+      if (isFundamentalType(getOperand(0).getType()) 
+          && isFundamentalType(getOperand(1).getType())) {
+        return false;
+      }
+      // Pointer arithmetic operations is pure.
+      if (isa<emitc::PointerType>(getOperand(0).getType()) 
+          && (isFundamentalType(getOperand(1).getType()) ||
+              isa<emitc::PointerType>(getOperand(1).getType()))) {
+        return false;
----------------
aniragil wrote:

- The operation `3 + p` is also valid.
- Why does the type being pointed to matter?
- Can instead include `emitc::PointerType` in `isFundamentalType()`?

https://github.com/llvm/llvm-project/pull/144990


More information about the Mlir-commits mailing list