[Mlir-commits] [mlir] 6496824 - [mlir][Arith] Fix bug in zero-extension range inference

Krzysztof Drewniak llvmlistbot at llvm.org
Tue Jan 10 13:41:19 PST 2023


Author: Krzysztof Drewniak
Date: 2023-01-10T21:41:13Z
New Revision: 6496824ebaf29a39239c1df1b508490382dca2f7

URL: https://github.com/llvm/llvm-project/commit/6496824ebaf29a39239c1df1b508490382dca2f7
DIFF: https://github.com/llvm/llvm-project/commit/6496824ebaf29a39239c1df1b508490382dca2f7.diff

LOG: [mlir][Arith] Fix bug in zero-extension range inference

D135089 extracted the extui code into a helper, but used fromSigned
instead of fromUnsigned.

Reviewed By: Mogball, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D141296

Added: 
    

Modified: 
    mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
    mlir/test/Dialect/Arith/int-range-interface.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
index 586c8e6a11aac..f23b61681d75a 100644
--- a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
+++ b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
@@ -469,9 +469,9 @@ void arith::MinUIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
 static ConstantIntRanges extUIRange(const ConstantIntRanges &range,
                                     Type destType) {
   unsigned destWidth = ConstantIntRanges::getStorageBitwidth(destType);
-  APInt smin = range.umin().zext(destWidth);
-  APInt smax = range.umax().zext(destWidth);
-  return ConstantIntRanges::fromSigned(smin, smax);
+  APInt umin = range.umin().zext(destWidth);
+  APInt umax = range.umax().zext(destWidth);
+  return ConstantIntRanges::fromUnsigned(umin, umax);
 }
 
 void arith::ExtUIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,

diff  --git a/mlir/test/Dialect/Arith/int-range-interface.mlir b/mlir/test/Dialect/Arith/int-range-interface.mlir
index 5b7085baf86c9..4c5f4095225d3 100644
--- a/mlir/test/Dialect/Arith/int-range-interface.mlir
+++ b/mlir/test/Dialect/Arith/int-range-interface.mlir
@@ -712,3 +712,21 @@ func.func @trunc_handles_small_signed_ranges(%arg0 : i16) -> i1 {
     %5 = arith.andi %3, %4 : i1
     func.return %5 : i1
 }
+
+/// Catch a bug that crept in during an earlier refactoring that made unsigned
+/// extension use the signed ranges
+
+// CHECK-LABEL: func.func @extui_uses_unsigned
+// CHECK: %[[true:.*]] = arith.constant true
+// CHECK: return %[[true]]
+func.func @extui_uses_unsigned(%arg0 : i32) -> i1 {
+    %ci32_smin = arith.constant 0x80000000 : i32
+    %ci32_smin_64 = arith.constant 0x80000000 : i64
+    %c0_i64 = arith.constant 0 : i64
+    %0 = arith.minui %arg0, %ci32_smin : i32
+    %1 = arith.extui %0 : i32 to i64
+    %2 = arith.cmpi sge, %1, %c0_i64 : i64
+    %3 = arith.cmpi ule, %1, %ci32_smin_64 : i64
+    %4 = arith.andi %2, %3 : i1
+    func.return %4 : i1
+}


        


More information about the Mlir-commits mailing list