[llvm] 36cc533 - [EarlyCSE][OpaquePointers]Replace assert with return for mask type check.

Denis Antrushin via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 06:15:07 PDT 2022


Author: Denis Antrushin
Date: 2022-08-08T16:14:42+03:00
New Revision: 36cc533471cb87ff6e9f44d9a3cd87f21369a87e

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

LOG: [EarlyCSE][OpaquePointers]Replace assert with return for mask type check.

When EarlyCSE tries to common vector masked loads/stores, it first checks that
they have same base operand and then assumes that this is enough for mask types
to be equal. This is true for typed pointers but false for opaque ones -
two loads of different vector sizes from same base pointer '%b' are the same,
`ptr %b`. (For typed pointers, `%b` was cast to vector pointer type so bases
were different).
Change assert to return from lambda `isSubmask` so this transformation properly
works with opaque pointers.

Reviewed By: nikic

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/EarlyCSE.cpp
    llvm/test/Transforms/EarlyCSE/opaque-ptr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index fd4882e2531e0..13616bb8dbcfc 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -881,8 +881,8 @@ class EarlyCSE {
       auto *Vec1 = dyn_cast<ConstantVector>(Mask1);
       if (!Vec0 || !Vec1)
         return false;
-      assert(Vec0->getType() == Vec1->getType() &&
-             "Masks should have the same type");
+      if (Vec0->getType() != Vec1->getType())
+        return false;
       for (int i = 0, e = Vec0->getNumOperands(); i != e; ++i) {
         Constant *Elem0 = Vec0->getOperand(i);
         Constant *Elem1 = Vec1->getOperand(i);

diff  --git a/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll b/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
index b05fc802ca250..1c995ab63a5c4 100644
--- a/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
+++ b/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
@@ -16,6 +16,23 @@ define i32 @
diff erent_types_load(ptr %p) {
   ret i32 %sub
 }
 
+define i32 @
diff erent_types_vector_load(ptr %p) {
+; CHECK-LABEL: @
diff erent_types_vector_load(
+; CHECK-NEXT:    [[V1:%.*]] = call <4 x i32> @llvm.masked.load.v4i32.p0(ptr [[P:%.*]], i32 4, <4 x i1> <i1 true, i1 true, i1 true, i1 false>, <4 x i32> poison)
+; CHECK-NEXT:    [[V2:%.*]] = call <8 x i32> @llvm.masked.load.v8i32.p0(ptr [[P]], i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false>, <8 x i32> poison)
+; CHECK-NEXT:    [[E1:%.*]] = extractelement <4 x i32> [[V1]], i32 0
+; CHECK-NEXT:    [[E2:%.*]] = extractelement <8 x i32> [[V2]], i32 6
+; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[E1]], [[E2]]
+; CHECK-NEXT:    ret i32 [[SUM]]
+;
+  %v1 = call <4 x i32> @llvm.masked.load.v4i32.p(ptr %p, i32 4, <4 x i1> <i1 true, i1 true, i1 true, i1 false>, <4 x i32> poison)
+  %v2 = call <8 x i32> @llvm.masked.load.v8i32.p(ptr %p, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false>, <8 x i32> poison)
+  %e1 = extractelement <4 x i32> %v1, i32 0
+  %e2 = extractelement <8 x i32> %v2, i32 6
+  %sum = add i32 %e1, %e2
+  ret i32 %sum
+}
+
 define i32 @
diff erent_types_store(ptr %p, i32 %a) {
 ; CHECK-LABEL: @
diff erent_types_store(
 ; CHECK-NEXT:    store i32 [[A:%.*]], ptr [[P:%.*]], align 4
@@ -41,3 +58,6 @@ define void @dse(ptr %p, i32 %i1, i8 %i2) {
   store i8 %i2, ptr %p
   ret void
 }
+
+declare <4 x i32> @llvm.masked.load.v4i32.p(ptr, i32 immarg, <4 x i1>, <4 x i32>)
+declare <8 x i32> @llvm.masked.load.v8i32.p(ptr, i32 immarg, <8 x i1>, <8 x i32>)


        


More information about the llvm-commits mailing list