Skip to content

[mlir][arith] Align shift Ops with LLVM instructions on allowed shift amounts #82133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2024

Conversation

ubfx
Copy link
Member

@ubfx ubfx commented Feb 17, 2024

This patch aligns the documentation of the shift Ops in arith with respective LLVM instructions. Specifically, it is now stated that shifting by an amount equal to the operand bitwidth returns poison.

Relevant discussion: https://discourse.llvm.org/t/some-question-on-the-semantics-of-the-arith-dialect/74861/10
Relevant issue: #80960

This patch aligns the documentation of the shift Ops in `arith` with
respective LLVM instructions. Specifically, it is now stated that
shifting by an amount equal to the operand bitwidth returns poison.
@llvmbot
Copy link
Member

llvmbot commented Feb 17, 2024

@llvm/pr-subscribers-mlir-arith

@llvm/pr-subscribers-mlir

Author: Felix Schneider (ubfx)

Changes

This patch aligns the documentation of the shift Ops in arith with respective LLVM instructions. Specifically, it is now stated that shifting by an amount equal to the operand bitwidth returns poison.


Full diff: https://github.com/llvm/llvm-project/pull/82133.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Arith/IR/ArithOps.td (+5-5)
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 4babbe80e285f7..c9df50d0395d1f 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -788,7 +788,7 @@ def Arith_ShLIOp : Arith_IntBinaryOpWithOverflowFlags<"shli"> {
     The `shli` operation shifts the integer value of the first operand to the left 
     by the integer value of the second operand. The second operand is interpreted as 
     unsigned. The low order bits are filled with zeros. If the value of the second 
-    operand is greater than the bitwidth of the first operand, then the 
+    operand is greater or equal than the bitwidth of the first operand, then the
     operation returns poison.
 
     This op supports `nuw`/`nsw` overflow flags which stands stand for
@@ -818,8 +818,8 @@ def Arith_ShRUIOp : Arith_TotalIntBinaryOp<"shrui"> {
     The `shrui` operation shifts an integer value of the first operand to the right 
     by the value of the second operand. The first operand is interpreted as unsigned,
     and the second operand is interpreted as unsigned. The high order bits are always 
-    filled with zeros. If the value of the second operand is greater than the bitwidth
-    of the first operand, then the operation returns poison.
+    filled with zeros. If the value of the second operand is greater or equal than the
+    bitwidth of the first operand, then the operation returns poison.
 
     Example:
 
@@ -844,8 +844,8 @@ def Arith_ShRSIOp : Arith_TotalIntBinaryOp<"shrsi"> {
     and the second operand is interpreter as unsigned. The high order bits in the 
     output are filled with copies of the most-significant bit of the shifted value 
     (which means that the sign of the value is preserved). If the value of the second 
-    operand is greater than bitwidth of the first operand, then the operation returns 
-    poison.
+    operand is greater or equal than bitwidth of the first operand, then the operation
+    returns poison.
 
     Example:
 

@ubfx ubfx requested a review from gysit February 17, 2024 22:24
Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of the bug, shouldn't the folder be updated as well to return poison?

@joker-eph
Copy link
Collaborator

I think this is the line to change?

bounded = b.ule(b.getBitWidth());

Also any other op affected in a similar way?

@kuhar
Copy link
Member

kuhar commented Feb 18, 2024

In the context of the bug, shouldn't the folder be updated as well to return poison?

Right now we don't have any folders/canon patterns that produce poison; the rationale is here: https://discourse.llvm.org/t/some-question-on-the-semantics-of-the-arith-dialect/74861/2.

The shift folders should be updated not to fold when the shit amount equals the bitwidth.

@ubfx
Copy link
Member Author

ubfx commented Feb 18, 2024

Also any other op affected in a similar way?

This issue #81228 seems to hint to something similar, but I'm still trying to find the root cause.

@ubfx ubfx changed the title [mlir][arith] Update documentation of shift Ops on allowed shift amounts [mlir][arith] Align shift Ops with LLVM instructions on allowed shift amounts Feb 18, 2024
Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ubfx ubfx merged commit 1a8c613 into llvm:main Feb 18, 2024
@ubfx ubfx deleted the arith-shift-doc-poison branch February 18, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants