[llvm] b5fa357 - [Test] Add test showing missing canonicalization opportunity in SCEV

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 03:17:38 PST 2023


Author: Max Kazantsev
Date: 2023-01-11T18:17:20+07:00
New Revision: b5fa3574b5e4d9d69410919a618e207da1977c70

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

LOG: [Test] Add test showing missing canonicalization opportunity in SCEV

We could have same SCEVs for the following expressions:
  zext(umin(x, y)) and umin(zext(x), zext(y));
  zext(umax(x, y)) and umax(zext(x), zext(y))
  sext(smin(x, y)) and smin(zsxt(x), sext(y));
  sext(smax(x, y)) and smax(sext(x), sext(y)).

Added: 
    llvm/test/Analysis/ScalarEvolution/ext_min_max.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/ext_min_max.ll b/llvm/test/Analysis/ScalarEvolution/ext_min_max.ll
new file mode 100644
index 0000000000000..d08052931cb4e
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/ext_min_max.ll
@@ -0,0 +1,122 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
+
+; TODO: Make sure that zext(umin(x, y)) has same SCEV as umin(zext(x), zext(y)).
+; Equality proof: https://alive2.llvm.org/ce/z/vdsvmp
+define i1 @test_umin(i32 %x, i32 %y) {
+; CHECK-LABEL: 'test_umin'
+; CHECK-NEXT:  Classifying expressions for: @test_umin
+; CHECK-NEXT:    %umin_x_y = select i1 %cmp_x_y, i32 %x, i32 %y
+; CHECK-NEXT:    --> (%x umin %y) U: full-set S: full-set
+; CHECK-NEXT:    %zext_umin_x_y = zext i32 %umin_x_y to i64
+; CHECK-NEXT:    --> (zext i32 (%x umin %y) to i64) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:    %zext_x = zext i32 %x to i64
+; CHECK-NEXT:    --> (zext i32 %x to i64) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:    %zext_y = zext i32 %y to i64
+; CHECK-NEXT:    --> (zext i32 %y to i64) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:    %umin_zext_x_zext_y = select i1 %cmp_zext_x_zext_y, i64 %zext_x, i64 %zext_y
+; CHECK-NEXT:    --> ((zext i32 %x to i64) umin (zext i32 %y to i64)) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:  Determining loop execution counts for: @test_umin
+;
+  %cmp_x_y = icmp ult i32 %x, %y
+  %umin_x_y = select i1 %cmp_x_y, i32 %x, i32 %y
+  %zext_umin_x_y = zext i32 %umin_x_y to i64
+
+  %zext_x = zext i32 %x to i64
+  %zext_y = zext i32 %y to i64
+  %cmp_zext_x_zext_y = icmp ult i64 %zext_x, %zext_y
+  %umin_zext_x_zext_y = select i1 %cmp_zext_x_zext_y, i64 %zext_x, i64 %zext_y
+
+  %they_are_same = icmp eq i64 %zext_umin_x_y, %umin_zext_x_zext_y
+  ret i1 %they_are_same
+}
+
+; TODO: Make sure that zext(umax(x, y)) has same SCEV as umax(zext(x), zext(y)).
+; Equality proof: https://alive2.llvm.org/ce/z/5JHgxZ
+define i1 @test_umax(i32 %x, i32 %y) {
+; CHECK-LABEL: 'test_umax'
+; CHECK-NEXT:  Classifying expressions for: @test_umax
+; CHECK-NEXT:    %umax_x_y = select i1 %cmp_x_y, i32 %y, i32 %x
+; CHECK-NEXT:    --> (%x umax %y) U: full-set S: full-set
+; CHECK-NEXT:    %zext_umax_x_y = zext i32 %umax_x_y to i64
+; CHECK-NEXT:    --> (zext i32 (%x umax %y) to i64) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:    %zext_x = zext i32 %x to i64
+; CHECK-NEXT:    --> (zext i32 %x to i64) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:    %zext_y = zext i32 %y to i64
+; CHECK-NEXT:    --> (zext i32 %y to i64) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:    %umax_zext_x_zext_y = select i1 %cmp_zext_x_zext_y, i64 %zext_y, i64 %zext_x
+; CHECK-NEXT:    --> ((zext i32 %x to i64) umax (zext i32 %y to i64)) U: [0,4294967296) S: [0,4294967296)
+; CHECK-NEXT:  Determining loop execution counts for: @test_umax
+;
+  %cmp_x_y = icmp ult i32 %x, %y
+  %umax_x_y = select i1 %cmp_x_y, i32 %y, i32 %x
+  %zext_umax_x_y = zext i32 %umax_x_y to i64
+
+  %zext_x = zext i32 %x to i64
+  %zext_y = zext i32 %y to i64
+  %cmp_zext_x_zext_y = icmp ult i64 %zext_x, %zext_y
+  %umax_zext_x_zext_y = select i1 %cmp_zext_x_zext_y, i64 %zext_y, i64 %zext_x
+
+  %they_are_same = icmp eq i64 %zext_umax_x_y, %umax_zext_x_zext_y
+  ret i1 %they_are_same
+}
+
+; TODO: Make sure that sext(smin(x, y)) has same SCEV as smin(sext(x), sext(y)).
+; Equality proof: https://alive2.llvm.org/ce/z/HhYHzR
+define i1 @test_smin(i32 %x, i32 %y) {
+; CHECK-LABEL: 'test_smin'
+; CHECK-NEXT:  Classifying expressions for: @test_smin
+; CHECK-NEXT:    %smin_x_y = select i1 %cmp_x_y, i32 %x, i32 %y
+; CHECK-NEXT:    --> (%x smin %y) U: full-set S: full-set
+; CHECK-NEXT:    %sext_smin_x_y = sext i32 %smin_x_y to i64
+; CHECK-NEXT:    --> (sext i32 (%x smin %y) to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:    %sext_x = sext i32 %x to i64
+; CHECK-NEXT:    --> (sext i32 %x to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:    %sext_y = sext i32 %y to i64
+; CHECK-NEXT:    --> (sext i32 %y to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:    %smin_sext_x_sext_y = select i1 %cmp_sext_x_sext_y, i64 %sext_x, i64 %sext_y
+; CHECK-NEXT:    --> ((sext i32 %x to i64) smin (sext i32 %y to i64)) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:  Determining loop execution counts for: @test_smin
+;
+  %cmp_x_y = icmp slt i32 %x, %y
+  %smin_x_y = select i1 %cmp_x_y, i32 %x, i32 %y
+  %sext_smin_x_y = sext i32 %smin_x_y to i64
+
+  %sext_x = sext i32 %x to i64
+  %sext_y = sext i32 %y to i64
+  %cmp_sext_x_sext_y = icmp slt i64 %sext_x, %sext_y
+  %smin_sext_x_sext_y = select i1 %cmp_sext_x_sext_y, i64 %sext_x, i64 %sext_y
+
+  %they_are_same = icmp eq i64 %sext_smin_x_y, %smin_sext_x_sext_y
+  ret i1 %they_are_same
+}
+
+; TODO: Make sure that sext(smax(x, y)) has same SCEV as smax(sext(x), sext(y)).
+; Equality proof: https://alive2.llvm.org/ce/z/uou_u-
+define i1 @test_smax(i32 %x, i32 %y) {
+; CHECK-LABEL: 'test_smax'
+; CHECK-NEXT:  Classifying expressions for: @test_smax
+; CHECK-NEXT:    %smax_x_y = select i1 %cmp_x_y, i32 %y, i32 %x
+; CHECK-NEXT:    --> (%x smax %y) U: full-set S: full-set
+; CHECK-NEXT:    %sext_smax_x_y = sext i32 %smax_x_y to i64
+; CHECK-NEXT:    --> (sext i32 (%x smax %y) to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:    %sext_x = sext i32 %x to i64
+; CHECK-NEXT:    --> (sext i32 %x to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:    %sext_y = sext i32 %y to i64
+; CHECK-NEXT:    --> (sext i32 %y to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:    %smax_sext_x_sext_y = select i1 %cmp_sext_x_sext_y, i64 %sext_y, i64 %sext_x
+; CHECK-NEXT:    --> ((sext i32 %x to i64) smax (sext i32 %y to i64)) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
+; CHECK-NEXT:  Determining loop execution counts for: @test_smax
+;
+  %cmp_x_y = icmp slt i32 %x, %y
+  %smax_x_y = select i1 %cmp_x_y, i32 %y, i32 %x
+  %sext_smax_x_y = sext i32 %smax_x_y to i64
+
+  %sext_x = sext i32 %x to i64
+  %sext_y = sext i32 %y to i64
+  %cmp_sext_x_sext_y = icmp slt i64 %sext_x, %sext_y
+  %smax_sext_x_sext_y = select i1 %cmp_sext_x_sext_y, i64 %sext_y, i64 %sext_x
+
+  %they_are_same = icmp eq i64 %sext_smax_x_y, %smax_sext_x_sext_y
+  ret i1 %they_are_same
+}


        


More information about the llvm-commits mailing list