[llvm] [AMDGPU] Added isCommutable attribute to V_ADD_NC_U16 (PR #111789)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 02:20:02 PDT 2024


================
@@ -870,9 +870,11 @@ let SubtargetPredicate = isGFX10Plus in {
     def : PermlanePat<int_amdgcn_permlane16, V_PERMLANE16_B32_e64, vt>;
     def : PermlanePat<int_amdgcn_permlanex16, V_PERMLANEX16_B32_e64, vt>;
   }
-
-  defm V_ADD_NC_U16 : VOP3Inst <"v_add_nc_u16", VOP3_Profile<VOP_I16_I16_I16, VOP3_OPSEL>, add>;
-  defm V_SUB_NC_U16 : VOP3Inst <"v_sub_nc_u16", VOP3_Profile<VOP_I16_I16_I16, VOP3_OPSEL>, sub>;
+  
+  let isCommutable = 1 in {
+    defm V_ADD_NC_U16 : VOP3Inst <"v_add_nc_u16", VOP3_Profile<VOP_I16_I16_I16, VOP3_OPSEL>, add>;
+    defm V_SUB_NC_U16 : VOP3Inst <"v_sub_nc_u16", VOP3_Profile<VOP_I16_I16_I16, VOP3_OPSEL>, sub>;
+  } // End isCommutable = 1
----------------
graphite-app[bot] wrote:

The `V_SUB_NC_U16` instruction is incorrectly marked as commutable. Subtraction is not a commutative operation, and marking it as such could lead to incorrect code generation. Consider removing `V_SUB_NC_U16` from the `isCommutable = 1` block to prevent potential issues. The `V_ADD_NC_U16` instruction can remain within this block as addition is commutative.

*Spotted by [Graphite Reviewer](https://app.graphite.dev/graphite-reviewer/?org=llvm&ref=ai-review-comment)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>

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


More information about the llvm-commits mailing list