[llvm] 02b38ba - [ConstFold] Salvage some div/rem folding test (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 01:03:11 PDT 2022


Author: Nikita Popov
Date: 2022-07-06T10:03:03+02:00
New Revision: 02b38ba8aa6ea32be5198849fff93929a117afe6

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

LOG: [ConstFold] Salvage some div/rem folding test (NFC)

The div/rem constant expressions are going away in D129148. Convert
some tests to use InstSimplify instead, to show that the constant
folding still happens.

Added: 
    

Modified: 
    llvm/test/Assembler/ConstantExprFold.ll
    llvm/test/Transforms/InstSimplify/ConstProp/2009-06-20-constexpr-zero-lhs.ll
    llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll
    llvm/test/Transforms/InstSimplify/div.ll

Removed: 
    llvm/test/Transforms/InstSimplify/ConstProp/2007-02-23-sdiv.ll


################################################################################
diff  --git a/llvm/test/Assembler/ConstantExprFold.ll b/llvm/test/Assembler/ConstantExprFold.ll
index 8df42688b64ba..30c6f04333181 100644
--- a/llvm/test/Assembler/ConstantExprFold.ll
+++ b/llvm/test/Assembler/ConstantExprFold.ll
@@ -11,8 +11,6 @@
 @add = global i64* inttoptr (i64 add (i64 ptrtoint (i64* @A to i64), i64 0) to i64*) ; X + 0 == X
 @sub = global i64* inttoptr (i64 sub (i64 ptrtoint (i64* @A to i64), i64 0) to i64*) ; X - 0 == X
 @mul = global i64* inttoptr (i64 mul (i64 ptrtoint (i64* @A to i64), i64 0) to i64*) ; X * 0 == 0
- at sdiv = global i64* inttoptr (i64 sdiv (i64 ptrtoint (i64* @A to i64), i64 1) to i64*) ; X / 1 == X
- at srem = global i64* inttoptr (i64 srem (i64 ptrtoint (i64* @A to i64), i64 1) to i64*) ; X % 1 == 0
 @and1 = global i64* inttoptr (i64 and (i64 ptrtoint (i64* @A to i64), i64 0) to i64*) ; X & 0 == 0
 @and2 = global i64* inttoptr (i64 and (i64 ptrtoint (i64* @A to i64), i64 -1) to i64*) ; X & -1 == X
 @or = global i64 or (i64 ptrtoint (i64* @A to i64), i64 -1)  ; X | -1 == -1
@@ -44,8 +42,6 @@
 ; CHECK: @[[ADD:[a-zA-Z0-9_$"\\.-]+]] = global i64* @A
 ; CHECK: @[[SUB:[a-zA-Z0-9_$"\\.-]+]] = global i64* @A
 ; CHECK: @[[MUL:[a-zA-Z0-9_$"\\.-]+]] = global i64* null
-; CHECK: @[[SDIV:[a-zA-Z0-9_$"\\.-]+]] = global i64* @A
-; CHECK: @[[SREM:[a-zA-Z0-9_$"\\.-]+]] = global i64* null
 ; CHECK: @[[AND1:[a-zA-Z0-9_$"\\.-]+]] = global i64* null
 ; CHECK: @[[AND2:[a-zA-Z0-9_$"\\.-]+]] = global i64* @A
 ; CHECK: @[[OR:[a-zA-Z0-9_$"\\.-]+]] = global i64 -1

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/2007-02-23-sdiv.ll b/llvm/test/Transforms/InstSimplify/ConstProp/2007-02-23-sdiv.ll
deleted file mode 100644
index 75f58b573fff5..0000000000000
--- a/llvm/test/Transforms/InstSimplify/ConstProp/2007-02-23-sdiv.ll
+++ /dev/null
@@ -1,5 +0,0 @@
-; RUN: llvm-as < %s | llvm-dis | grep "global i32 0"
-; PR1215
-
- at G = global i32 sdiv (i32 0, i32 -1)
-

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/2009-06-20-constexpr-zero-lhs.ll b/llvm/test/Transforms/InstSimplify/ConstProp/2009-06-20-constexpr-zero-lhs.ll
index a8c34b90ed05a..6452a167cdd1d 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/2009-06-20-constexpr-zero-lhs.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/2009-06-20-constexpr-zero-lhs.ll
@@ -1,10 +1,6 @@
 ; RUN: llvm-as < %s | llvm-dis | not grep ptrtoint
 ; PR4424
 @G = external global i32
- at test1 = constant i32 sdiv (i32 0, i32 ptrtoint (ptr @G to i32))
- at test2 = constant i32 udiv (i32 0, i32 ptrtoint (ptr @G to i32))
- at test3 = constant i32 srem (i32 0, i32 ptrtoint (ptr @G to i32))
- at test4 = constant i32 urem (i32 0, i32 ptrtoint (ptr @G to i32))
 @test5 = constant i32 lshr (i32 0, i32 ptrtoint (ptr @G to i32))
 @test6 = constant i32 ashr (i32 0, i32 ptrtoint (ptr @G to i32))
 @test7 = constant i32 shl (i32 0, i32 ptrtoint (ptr @G to i32))

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll b/llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll
index eac4971f8a8b8..04a8f7c62ebb6 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll
@@ -11,15 +11,6 @@
 @C = global i1 mul (i1 icmp ult (ptr @X, ptr @Y), i1 icmp ult (ptr @X, ptr @Z))
 ; CHECK: @C = global i1 and (i1 icmp ult (ptr @X, ptr @Y), i1 icmp ult (ptr @X, ptr @Z))
 
- at D = global i1 sdiv (i1 icmp ult (ptr @X, ptr @Y), i1 icmp ult (ptr @X, ptr @Z))
-; CHECK: @D = global i1 icmp ult (ptr @X, ptr @Y)
- at E = global i1 udiv (i1 icmp ult (ptr @X, ptr @Y), i1 icmp ult (ptr @X, ptr @Z))
-; CHECK: @E = global i1 icmp ult (ptr @X, ptr @Y)
- at F = global i1 srem (i1 icmp ult (ptr @X, ptr @Y), i1 icmp ult (ptr @X, ptr @Z))
-; CHECK: @F = global i1 false 
- at G = global i1 urem (i1 icmp ult (ptr @X, ptr @Y), i1 icmp ult (ptr @X, ptr @Z))
-; CHECK: @G = global i1 false 
-
 @H = global i1 icmp ule (ptr @X, ptr @Y)
 ; CHECK: @H = global i1 icmp ule (ptr @X, ptr @Y)
 

diff  --git a/llvm/test/Transforms/InstSimplify/div.ll b/llvm/test/Transforms/InstSimplify/div.ll
index d2989f5cba7e7..0d89fc8aff3b3 100644
--- a/llvm/test/Transforms/InstSimplify/div.ll
+++ b/llvm/test/Transforms/InstSimplify/div.ll
@@ -226,4 +226,112 @@ define i8 @sdiv_minusone_divisor() {
   ret i8 %v
 }
 
+ at g = external global i64
+ at g2 = external global i64
+
+define i64 @const_sdiv_one() {
+; CHECK-LABEL: @const_sdiv_one(
+; CHECK-NEXT:    ret i64 ptrtoint (ptr @g to i64)
+;
+  %div = sdiv i64 ptrtoint (ptr @g to i64), 1
+  ret i64 %div
+}
+
+define i64 @const_srem_one() {
+; CHECK-LABEL: @const_srem_one(
+; CHECK-NEXT:    ret i64 0
+;
+  %rem = srem i64 ptrtoint (ptr @g to i64), 1
+  ret i64 %rem
+}
+
+define i64 @const_udiv_one() {
+; CHECK-LABEL: @const_udiv_one(
+; CHECK-NEXT:    ret i64 ptrtoint (ptr @g to i64)
+;
+  %div = udiv i64 ptrtoint (ptr @g to i64), 1
+  ret i64 %div
+}
+
+define i64 @const_urem_one() {
+; CHECK-LABEL: @const_urem_one(
+; CHECK-NEXT:    ret i64 0
+;
+  %rem = urem i64 ptrtoint (ptr @g to i64), 1
+  ret i64 %rem
+}
+
+define i64 @const_sdiv_zero() {
+; CHECK-LABEL: @const_sdiv_zero(
+; CHECK-NEXT:    ret i64 0
+;
+  %div = sdiv i64 0, ptrtoint (ptr @g to i64)
+  ret i64 %div
+}
+
+define i64 @const_srem_zero() {
+; CHECK-LABEL: @const_srem_zero(
+; CHECK-NEXT:    ret i64 0
+;
+  %rem = srem i64 0, ptrtoint (ptr @g to i64)
+  ret i64 %rem
+}
+
+define i64 @const_udiv_zero() {
+; CHECK-LABEL: @const_udiv_zero(
+; CHECK-NEXT:    ret i64 0
+;
+  %div = udiv i64 0, ptrtoint (ptr @g to i64)
+  ret i64 %div
+}
+
+define i64 @const_urem_zero() {
+; CHECK-LABEL: @const_urem_zero(
+; CHECK-NEXT:    ret i64 0
+;
+  %rem = urem i64 0, ptrtoint (ptr @g to i64)
+  ret i64 %rem
+}
+
+define i64 @const_sdiv_zero_negone() {
+; CHECK-LABEL: @const_sdiv_zero_negone(
+; CHECK-NEXT:    ret i64 0
+;
+  %div = sdiv i64 0, -1
+  ret i64 %div
+}
+
+define i1 @const_sdiv_i1() {
+; CHECK-LABEL: @const_sdiv_i1(
+; CHECK-NEXT:    ret i1 ptrtoint (ptr @g to i1)
+;
+  %div = sdiv i1 ptrtoint (ptr @g to i1), ptrtoint (ptr @g2 to i1)
+  ret i1 %div
+}
+
+define i1 @const_srem_1() {
+; CHECK-LABEL: @const_srem_1(
+; CHECK-NEXT:    ret i1 false
+;
+  %rem = srem i1 ptrtoint (ptr @g to i1), ptrtoint (ptr @g2 to i1)
+  ret i1 %rem
+}
+
+define i1 @const_udiv_i1() {
+; CHECK-LABEL: @const_udiv_i1(
+; CHECK-NEXT:    ret i1 ptrtoint (ptr @g to i1)
+;
+  %div = udiv i1 ptrtoint (ptr @g to i1), ptrtoint (ptr @g2 to i1)
+  ret i1 %div
+}
+
+define i1 @const_urem_1() {
+; CHECK-LABEL: @const_urem_1(
+; CHECK-NEXT:    ret i1 false
+;
+  %rem = urem i1 ptrtoint (ptr @g to i1), ptrtoint (ptr @g2 to i1)
+  ret i1 %rem
+}
+
+
 !0 = !{i32 0, i32 3}


        


More information about the llvm-commits mailing list