[Mlir-commits] [mlir] b6a2e33 - [mlir][llvm] Fix bug in constant import from LLVM IR.

Tobias Gysi llvmlistbot at llvm.org
Mon Feb 6 01:12:13 PST 2023


Author: Tobias Gysi
Date: 2023-02-06T10:10:48+01:00
New Revision: b6a2e33500cd29c8cce40acd08ff1dbd7559656f

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

LOG: [mlir][llvm] Fix bug in constant import from LLVM IR.

The revision addresses a bug during constant expression traversal
when importing LLVM IR. A constant expression may have cyclic
dependencies, for example, when a constant is initialized with its
address. This revision extends the constant expression traversal
to detect cyclic dependencies and adds a test to verify this
case is handled properly.

Reviewed By: Dinistro

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

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/ModuleImport.cpp
    mlir/test/Target/LLVMIR/Import/constant.ll
    mlir/test/Target/LLVMIR/Import/global-variables.ll
    mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll
    mlir/test/Target/LLVMIR/Import/incorrect-constexpr-inst-caching.ll

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index e0e11cf0be1b6..4b44819005341 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -859,37 +859,57 @@ ModuleImport::convertGlobalCtorsAndDtors(llvm::GlobalVariable *globalVar) {
 
 SetVector<llvm::Constant *>
 ModuleImport::getConstantsToConvert(llvm::Constant *constant) {
-  // Traverse the constant dependencies in post order.
-  SmallVector<llvm::Constant *> workList;
-  SmallVector<llvm::Constant *> orderedList;
-  workList.push_back(constant);
+  // Return the empty set if the constant has been translated before.
+  if (valueMapping.count(constant))
+    return {};
+
+  // Traverse the constants in post-order and stop the traversal if a constant
+  // already has a `valueMapping` from an earlier constant translation or if the
+  // constant is traversed a second time.
+  SetVector<llvm::Constant *> orderedSet;
+  SetVector<llvm::Constant *> workList;
+  DenseMap<llvm::Constant *, SmallVector<llvm::Constant *>> adjacencyLists;
+  workList.insert(constant);
   while (!workList.empty()) {
-    llvm::Constant *current = workList.pop_back_val();
-    // Skip constants that have been converted before and store all other ones.
-    if (valueMapping.count(current))
+    llvm::Constant *current = workList.back();
+    // Collect all dependencies of the current constant and add them to the
+    // adjacency list if none has been computed before.
+    auto adjacencyIt = adjacencyLists.find(current);
+    if (adjacencyIt == adjacencyLists.end()) {
+      adjacencyIt = adjacencyLists.try_emplace(current).first;
+      // Add all constant operands to the adjacency list and skip any other
+      // values such as basic block addresses.
+      for (llvm::Value *operand : current->operands())
+        if (auto *constDependency = dyn_cast<llvm::Constant>(operand))
+          adjacencyIt->getSecond().push_back(constDependency);
+      // Use the getElementValue method to add the dependencies of zero
+      // initialized aggregate constants since they do not take any operands.
+      if (auto *constAgg = dyn_cast<llvm::ConstantAggregateZero>(current)) {
+        unsigned numElements = constAgg->getElementCount().getFixedValue();
+        for (unsigned i = 0, e = numElements; i != e; ++i)
+          adjacencyIt->getSecond().push_back(constAgg->getElementValue(i));
+      }
+    }
+    // Add the current constant to the `orderedSet` of the traversed nodes if
+    // all its dependencies have been traversed before. Additionally, remove the
+    // constant from the `workList` and continue the traversal.
+    if (adjacencyIt->getSecond().empty()) {
+      orderedSet.insert(current);
+      workList.pop_back();
       continue;
-    orderedList.push_back(current);
-    // Add the current constant's dependencies to the work list. Only add
-    // constant dependencies and skip any other values such as basic block
-    // addresses.
-    for (llvm::Value *operand : current->operands())
-      if (auto *constDependency = dyn_cast<llvm::Constant>(operand))
-        workList.push_back(constDependency);
-    // Use the `getElementValue` method to add the dependencies of zero
-    // initialized aggregate constants since they do not take any operands.
-    if (auto *constAgg = dyn_cast<llvm::ConstantAggregateZero>(current)) {
-      unsigned numElements = constAgg->getElementCount().getFixedValue();
-      for (unsigned i = 0, e = numElements; i != e; ++i)
-        workList.push_back(constAgg->getElementValue(i));
     }
+    // Add the next dependency from the adjacency list to the `workList` and
+    // continue the traversal. Remove the dependency from the adjacency list to
+    // mark that it has been processed. Only enqueue the dependency if it has no
+    // `valueMapping` from an earlier translation and if it has not been
+    // enqueued before.
+    llvm::Constant *dependency = adjacencyIt->getSecond().pop_back_val();
+    if (valueMapping.count(dependency) || workList.count(dependency) ||
+        orderedSet.count(dependency))
+      continue;
+    workList.insert(dependency);
   }
 
-  // Add the constants in reverse post order to the result set to ensure all
-  // dependencies are satisfied. Avoid storing duplicates since LLVM constants
-  // are uniqued and only one `valueMapping` entry per constant is possible.
-  SetVector<llvm::Constant *> orderedSet;
-  for (llvm::Constant *orderedConst : llvm::reverse(orderedList))
-    orderedSet.insert(orderedConst);
   return orderedSet;
 }
 

diff  --git a/mlir/test/Target/LLVMIR/Import/constant.ll b/mlir/test/Target/LLVMIR/Import/constant.ll
index 2e8be550c45ff..85cde7b1bcfef 100644
--- a/mlir/test/Target/LLVMIR/Import/constant.ll
+++ b/mlir/test/Target/LLVMIR/Import/constant.ll
@@ -60,10 +60,10 @@ define ptr @null_constant() {
 
 ; CHECK-LABEL: @gep_const_expr
 define ptr @gep_const_expr() {
-  ; CHECK:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr
-  ; CHECK:  %[[IDX:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32
-  ; CHECK:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr, i32) -> !llvm.ptr
-  ; CHECK:  llvm.return %[[GEP]] : !llvm.ptr
+  ; CHECK-DAG:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr
+  ; CHECK-DAG:  %[[IDX:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32
+  ; CHECK-DAG:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr, i32) -> !llvm.ptr
+  ; CHECK-DAG:  llvm.return %[[GEP]] : !llvm.ptr
   ret ptr getelementptr (i32, ptr @global, i32 2)
 }
 
@@ -73,14 +73,14 @@ define ptr @gep_const_expr() {
 
 ; CHECK-LABEL: @const_expr_with_duplicate
 define i64 @const_expr_with_duplicate() {
-  ; CHECK:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr
-  ; CHECK:  %[[IDX:[0-9]+]] = llvm.mlir.constant(7 : i32) : i32
-  ; CHECK:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr, i32) -> !llvm.ptr
-  ; CHECK:  %[[DUP:[0-9]+]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr to i64
+  ; CHECK-DAG:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr
+  ; CHECK-DAG:  %[[IDX:[0-9]+]] = llvm.mlir.constant(7 : i32) : i32
+  ; CHECK-DAG:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr, i32) -> !llvm.ptr
+  ; CHECK-DAG:  %[[DUP:[0-9]+]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr to i64
 
   ; Verify the duplicate sub expression is converted only once.
-  ; CHECK:  %[[SUM:[0-9]+]] = llvm.add %[[DUP]], %[[DUP]] : i64
-  ; CHECK:  llvm.return %[[SUM]] : i64
+  ; CHECK-DAG:  %[[SUM:[0-9]+]] = llvm.add %[[DUP]], %[[DUP]] : i64
+  ; CHECK-DAG:  llvm.return %[[SUM]] : i64
   ret i64 add (i64 ptrtoint (ptr getelementptr (i32, ptr @global, i32 7) to i64),
                i64 ptrtoint (ptr getelementptr (i32, ptr @global, i32 7) to i64))
 }
@@ -92,27 +92,27 @@ define i64 @const_expr_with_duplicate() {
 ; CHECK-LABEL: @const_expr_with_aggregate()
 define i64 @const_expr_with_aggregate() {
   ; Compute the vector elements.
-  ; CHECK:  %[[VAL1:[0-9]+]] = llvm.mlir.constant(33 : i64) : i64
-  ; CHECK:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr
-  ; CHECK:  %[[IDX1:[0-9]+]] = llvm.mlir.constant(7 : i32) : i32
-  ; CHECK:  %[[GEP1:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX1]]] : (!llvm.ptr, i32) -> !llvm.ptr
-  ; CHECK:  %[[VAL2:[0-9]+]] = llvm.ptrtoint %[[GEP1]] : !llvm.ptr to i64
+  ; CHECK-DAG:  %[[VAL1:[0-9]+]] = llvm.mlir.constant(33 : i64) : i64
+  ; CHECK-DAG:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr
+  ; CHECK-DAG:  %[[IDX1:[0-9]+]] = llvm.mlir.constant(7 : i32) : i32
+  ; CHECK-DAG:  %[[GEP1:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX1]]] : (!llvm.ptr, i32) -> !llvm.ptr
+  ; CHECK-DAG:  %[[VAL2:[0-9]+]] = llvm.ptrtoint %[[GEP1]] : !llvm.ptr to i64
 
   ; Fill the vector.
-  ; CHECK:  %[[VEC1:[0-9]+]] = llvm.mlir.undef : vector<2xi64>
-  ; CHECK:  %[[IDX2:[0-9]+]] = llvm.mlir.constant(0 : i32) : i32
-  ; CHECK:  %[[VEC2:[0-9]+]] = llvm.insertelement %[[VAL1]], %[[VEC1]][%[[IDX2]] : i32] : vector<2xi64>
-  ; CHECK:  %[[IDX3:[0-9]+]] = llvm.mlir.constant(1 : i32) : i32
-  ; CHECK:  %[[VEC3:[0-9]+]] = llvm.insertelement %[[VAL2]], %[[VEC2]][%[[IDX3]] : i32] : vector<2xi64>
-  ; CHECK:  %[[IDX4:[0-9]+]] = llvm.mlir.constant(42 : i32) : i32
+  ; CHECK-DAG:  %[[VEC1:[0-9]+]] = llvm.mlir.undef : vector<2xi64>
+  ; CHECK-DAG:  %[[IDX2:[0-9]+]] = llvm.mlir.constant(0 : i32) : i32
+  ; CHECK-DAG:  %[[VEC2:[0-9]+]] = llvm.insertelement %[[VAL1]], %[[VEC1]][%[[IDX2]] : i32] : vector<2xi64>
+  ; CHECK-DAG:  %[[IDX3:[0-9]+]] = llvm.mlir.constant(1 : i32) : i32
+  ; CHECK-DAG:  %[[VEC3:[0-9]+]] = llvm.insertelement %[[VAL2]], %[[VEC2]][%[[IDX3]] : i32] : vector<2xi64>
+  ; CHECK-DAG:  %[[IDX4:[0-9]+]] = llvm.mlir.constant(42 : i32) : i32
 
   ; Compute the extract index.
-  ; CHECK:  %[[GEP2:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX4]]] : (!llvm.ptr, i32) -> !llvm.ptr
-  ; CHECK:  %[[IDX5:[0-9]+]] = llvm.ptrtoint %[[GEP2]] : !llvm.ptr to i64
+  ; CHECK-DAG:  %[[GEP2:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX4]]] : (!llvm.ptr, i32) -> !llvm.ptr
+  ; CHECK-DAG:  %[[IDX5:[0-9]+]] = llvm.ptrtoint %[[GEP2]] : !llvm.ptr to i64
 
   ; Extract the vector element.
-  ; CHECK:  %[[ELEM:[0-9]+]] = llvm.extractelement %[[VEC3]][%[[IDX5]] : i64] : vector<2xi64>
-  ; CHECK:  llvm.return %[[ELEM]] : i64
+  ; CHECK-DAG:  %[[ELEM:[0-9]+]] = llvm.extractelement %[[VEC3]][%[[IDX5]] : i64] : vector<2xi64>
+  ; CHECK-DAG:  llvm.return %[[ELEM]] : i64
   ret i64 extractelement (
     <2 x i64> <i64 33, i64 ptrtoint (ptr getelementptr (i32, ptr @global, i32 7) to i64)>,
     i64 ptrtoint (ptr getelementptr (i32, ptr @global, i32 42) to i64))
@@ -158,43 +158,43 @@ define i32 @function_address_after_def() {
 
 ; Verify the aggregate constant import.
 
-; CHECK:  %[[C0:.+]] = llvm.mlir.constant(9 : i32) : i32
-; CHECK:  %[[C1:.+]] = llvm.mlir.constant(4 : i8) : i8
-; CHECK:  %[[C2:.+]] = llvm.mlir.constant(8 : i16) : i16
-; CHECK:  %[[C3:.+]] = llvm.mlir.constant(7 : i32) : i32
-; CHECK:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"simple_agg_type", (i32, i8, i16, i32)>
-; CHECK:  %[[CHAIN0:.+]] = llvm.insertvalue %[[C0]], %[[ROOT]][0]
-; CHECK:  %[[CHAIN1:.+]] = llvm.insertvalue %[[C1]], %[[CHAIN0]][1]
-; CHECK:  %[[CHAIN2:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN1]][2]
-; CHECK:  %[[CHAIN3:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN2]][3]
-; CHECK:  llvm.return %[[CHAIN3]]
+; CHECK-DAG:  %[[C0:.+]] = llvm.mlir.constant(9 : i32) : i32
+; CHECK-DAG:  %[[C1:.+]] = llvm.mlir.constant(4 : i8) : i8
+; CHECK-DAG:  %[[C2:.+]] = llvm.mlir.constant(8 : i16) : i16
+; CHECK-DAG:  %[[C3:.+]] = llvm.mlir.constant(7 : i32) : i32
+; CHECK-DAG:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"simple_agg_type", (i32, i8, i16, i32)>
+; CHECK-DAG:  %[[CHAIN0:.+]] = llvm.insertvalue %[[C0]], %[[ROOT]][0]
+; CHECK-DAG:  %[[CHAIN1:.+]] = llvm.insertvalue %[[C1]], %[[CHAIN0]][1]
+; CHECK-DAG:  %[[CHAIN2:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN1]][2]
+; CHECK-DAG:  %[[CHAIN3:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN2]][3]
+; CHECK-DAG:  llvm.return %[[CHAIN3]]
 %simple_agg_type = type {i32, i8, i16, i32}
 @simple_agg = global %simple_agg_type {i32 9, i8 4, i16 8, i32 7}
 
-; CHECK:  %[[C1:.+]] = llvm.mlir.constant(1 : i32) : i32
-; CHECK:  %[[C2:.+]] = llvm.mlir.constant(2 : i8) : i8
-; CHECK:  %[[C3:.+]] = llvm.mlir.constant(3 : i16) : i16
-; CHECK:  %[[C4:.+]] = llvm.mlir.constant(4 : i32) : i32
-; CHECK:  %[[NESTED:.+]] = llvm.mlir.undef : !llvm.struct<"simple_agg_type", (i32, i8, i16, i32)>
-; CHECK:  %[[CHAIN0:.+]] = llvm.insertvalue %[[C1]], %[[NESTED]][0]
-; CHECK:  %[[CHAIN1:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN0]][1]
-; CHECK:  %[[CHAIN2:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN1]][2]
-; CHECK:  %[[CHAIN3:.+]] = llvm.insertvalue %[[C4]], %[[CHAIN2]][3]
-; CHECK:  %[[NULL:.+]] = llvm.mlir.null : !llvm.ptr
-; CHECK:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"nested_agg_type", (struct<"simple_agg_type", (i32, i8, i16, i32)>, ptr)>
-; CHECK:  %[[CHAIN4:.+]] = llvm.insertvalue %[[CHAIN3]], %[[ROOT]][0]
-; CHECK:  %[[CHAIN5:.+]] = llvm.insertvalue %[[NULL]], %[[CHAIN4]][1]
-; CHECK:  llvm.return %[[CHAIN5]]
+; CHECK-DAG:  %[[C1:.+]] = llvm.mlir.constant(1 : i32) : i32
+; CHECK-DAG:  %[[C2:.+]] = llvm.mlir.constant(2 : i8) : i8
+; CHECK-DAG:  %[[C3:.+]] = llvm.mlir.constant(3 : i16) : i16
+; CHECK-DAG:  %[[C4:.+]] = llvm.mlir.constant(4 : i32) : i32
+; CHECK-DAG:  %[[NESTED:.+]] = llvm.mlir.undef : !llvm.struct<"simple_agg_type", (i32, i8, i16, i32)>
+; CHECK-DAG:  %[[CHAIN0:.+]] = llvm.insertvalue %[[C1]], %[[NESTED]][0]
+; CHECK-DAG:  %[[CHAIN1:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN0]][1]
+; CHECK-DAG:  %[[CHAIN2:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN1]][2]
+; CHECK-DAG:  %[[CHAIN3:.+]] = llvm.insertvalue %[[C4]], %[[CHAIN2]][3]
+; CHECK-DAG:  %[[NULL:.+]] = llvm.mlir.null : !llvm.ptr
+; CHECK-DAG:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"nested_agg_type", (struct<"simple_agg_type", (i32, i8, i16, i32)>, ptr)>
+; CHECK-DAG:  %[[CHAIN4:.+]] = llvm.insertvalue %[[CHAIN3]], %[[ROOT]][0]
+; CHECK-DAG:  %[[CHAIN5:.+]] = llvm.insertvalue %[[NULL]], %[[CHAIN4]][1]
+; CHECK-DAG:  llvm.return %[[CHAIN5]]
 %nested_agg_type = type {%simple_agg_type, ptr}
 @nested_agg = global %nested_agg_type { %simple_agg_type{i32 1, i8 2, i16 3, i32 4}, ptr null }
 
-; CHECK:  %[[NULL:.+]] = llvm.mlir.null : !llvm.ptr
-; CHECK:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.vec<2 x ptr>
-; CHECK:  %[[P0:.+]] = llvm.mlir.constant(0 : i32) : i32
-; CHECK:  %[[CHAIN0:.+]] = llvm.insertelement %[[NULL]], %[[ROOT]][%[[P0]] : i32] : !llvm.vec<2 x ptr>
-; CHECK:  %[[P1:.+]] = llvm.mlir.constant(1 : i32) : i32
-; CHECK:  %[[CHAIN1:.+]] = llvm.insertelement %[[NULL]], %[[CHAIN0]][%[[P1]] : i32] : !llvm.vec<2 x ptr>
-; CHECK:  llvm.return %[[CHAIN1]] : !llvm.vec<2 x ptr>
+; CHECK-DAG:  %[[NULL:.+]] = llvm.mlir.null : !llvm.ptr
+; CHECK-DAG:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.vec<2 x ptr>
+; CHECK-DAG:  %[[P0:.+]] = llvm.mlir.constant(0 : i32) : i32
+; CHECK-DAG:  %[[CHAIN0:.+]] = llvm.insertelement %[[NULL]], %[[ROOT]][%[[P0]] : i32] : !llvm.vec<2 x ptr>
+; CHECK-DAG:  %[[P1:.+]] = llvm.mlir.constant(1 : i32) : i32
+; CHECK-DAG:  %[[CHAIN1:.+]] = llvm.insertelement %[[NULL]], %[[CHAIN0]][%[[P1]] : i32] : !llvm.vec<2 x ptr>
+; CHECK-DAG:  llvm.return %[[CHAIN1]] : !llvm.vec<2 x ptr>
 @vector_agg = global <2 x ptr> <ptr null, ptr null>
 
 ; // -----
@@ -214,3 +214,15 @@ define i64 @const_exprs_with_duplicate() {
   %2 = add i64 %1, ptrtoint (ptr getelementptr (i32, ptr @global, i32 42) to i64)
   ret i64 %2
 }
+
+; // -----
+
+; Verify the import of constant expressions with cyclic dependencies.
+
+ at cyclic = internal constant i64 mul (i64 ptrtoint (ptr @cyclic to i64), i64 ptrtoint (ptr @cyclic to i64))
+
+; CHECK-LABEL: @cyclic
+; CHECK:  %[[ADDR:.+]] = llvm.mlir.addressof @cyclic
+; CHECK:  %[[VAL0:.+]] = llvm.ptrtoint %[[ADDR]]
+; CHECK:  %[[VAL1:.+]] = llvm.mul %[[VAL0]], %[[VAL0]]
+; CHECK:  llvm.return %[[VAL1]]

diff  --git a/mlir/test/Target/LLVMIR/Import/global-variables.ll b/mlir/test/Target/LLVMIR/Import/global-variables.ll
index 5e68de9b2c01a..3b8be65eacd47 100644
--- a/mlir/test/Target/LLVMIR/Import/global-variables.ll
+++ b/mlir/test/Target/LLVMIR/Import/global-variables.ll
@@ -33,11 +33,10 @@
 
 ; CHECK: llvm.mlir.global internal constant @global_gep_const_expr
 ; CHECK-SAME:  {addr_space = 0 : i32, dso_local} : !llvm.ptr {
-; CHECK:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global_int : !llvm.ptr
-; CHECK:  %[[IDX:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32
-; CHECK:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr, i32) -> !llvm.ptr
-; CHECK:  llvm.return %[[GEP]] : !llvm.ptr
-; CHECK:  }
+; CHECK-DAG:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global_int : !llvm.ptr
+; CHECK-DAG:  %[[IDX:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32
+; CHECK-DAG:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr, i32) -> !llvm.ptr
+; CHECK-DAG   llvm.return %[[GEP]] : !llvm.ptr
 @global_gep_const_expr = internal constant ptr getelementptr (i32, ptr @global_int, i32 2)
 
 ; // -----

diff  --git a/mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll b/mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll
index 1953ecd683721..386709b3b09b3 100644
--- a/mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll
+++ b/mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll
@@ -8,23 +8,23 @@
 ; only wrote minimum level of checks.
 
 %my_struct = type {i32, ptr}
-; CHECK: llvm.mlir.constant(8 : i32) : i32
-; CHECK: llvm.mlir.addressof @str0 : !llvm.ptr
-; CHECK: llvm.mlir.constant(0 : i32) : i32
-; CHECK: llvm.getelementptr
-; CHECK: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
-; CHECK: llvm.insertvalue
-; CHECK: llvm.insertvalue
-; CHECK: llvm.mlir.constant(7 : i32) : i32
-; CHECK: llvm.mlir.addressof @str1 : !llvm.ptr
-; CHECK: llvm.getelementptr
-; CHECK: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
-; CHECK: llvm.insertvalue
-; CHECK: llvm.insertvalue
-; CHECK: llvm.mlir.undef : !llvm.array<2 x struct<"my_struct", (i32, ptr)>>
-; CHECK: llvm.insertvalue
-; CHECK: llvm.insertvalue
-; CHECK: llvm.return
+; CHECK-DAG: llvm.mlir.constant(8 : i32) : i32
+; CHECK-DAG: llvm.mlir.addressof @str0 : !llvm.ptr
+; CHECK-DAG: llvm.mlir.constant(0 : i32) : i32
+; CHECK-DAG: llvm.getelementptr
+; CHECK-DAG: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.mlir.constant(7 : i32) : i32
+; CHECK-DAG: llvm.mlir.addressof @str1 : !llvm.ptr
+; CHECK-DAG: llvm.getelementptr
+; CHECK-DAG: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.mlir.undef : !llvm.array<2 x struct<"my_struct", (i32, ptr)>>
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.return
 @str0 = private unnamed_addr constant [5 x i8] c"aaaa\00"
 @str1 = private unnamed_addr constant [5 x i8] c"bbbb\00"
 @g = global [2 x %my_struct] [%my_struct {i32 8, ptr getelementptr ([5 x i8], ptr @str0, i32 0, i32 1)}, %my_struct {i32 7, ptr getelementptr ([5 x i8], ptr @str1, i32 0, i32 1)}]

diff  --git a/mlir/test/Target/LLVMIR/Import/incorrect-constexpr-inst-caching.ll b/mlir/test/Target/LLVMIR/Import/incorrect-constexpr-inst-caching.ll
index 15957050e079a..75ba51550b1ea 100644
--- a/mlir/test/Target/LLVMIR/Import/incorrect-constexpr-inst-caching.ll
+++ b/mlir/test/Target/LLVMIR/Import/incorrect-constexpr-inst-caching.ll
@@ -5,26 +5,26 @@
 ; Thus, we only wrote minimum level of checks.
 
 %my_struct = type {i32, ptr}
-; CHECK: llvm.mlir.constant(8 : i32) : i32
-; CHECK: llvm.mlir.addressof @str0 : !llvm.ptr
-; CHECK: llvm.mlir.constant(0 : i32) : i32
-; CHECK: llvm.mlir.constant(1 : i32) : i32
-; CHECK: llvm.getelementptr
-; CHECK: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
-; CHECK: llvm.insertvalue
-; CHECK: llvm.insertvalue
-; CHECK: llvm.mlir.constant(7 : i32) : i32
-; CHECK: llvm.mlir.addressof @str1 : !llvm.ptr
-; CHECK: llvm.mlir.constant(2 : i32) : i32
-; CHECK: llvm.mlir.constant(3 : i32) : i32
-; CHECK: llvm.getelementptr
-; CHECK: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
-; CHECK: llvm.insertvalue
-; CHECK: llvm.insertvalue
-; CHECK: llvm.mlir.undef : !llvm.array<2 x struct<"my_struct", (i32, ptr)>>
-; CHECK: llvm.insertvalue
-; CHECK: llvm.insertvalue
-; CHECK: llvm.return
+; CHECK-DAG: llvm.mlir.constant(8 : i32) : i32
+; CHECK-DAG: llvm.mlir.addressof @str0 : !llvm.ptr
+; CHECK-DAG: llvm.mlir.constant(0 : i32) : i32
+; CHECK-DAG: llvm.mlir.constant(1 : i32) : i32
+; CHECK-DAG: llvm.getelementptr
+; CHECK-DAG: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.mlir.constant(7 : i32) : i32
+; CHECK-DAG: llvm.mlir.addressof @str1 : !llvm.ptr
+; CHECK-DAG: llvm.mlir.constant(2 : i32) : i32
+; CHECK-DAG: llvm.mlir.constant(3 : i32) : i32
+; CHECK-DAG: llvm.getelementptr
+; CHECK-DAG: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)>
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.mlir.undef : !llvm.array<2 x struct<"my_struct", (i32, ptr)>>
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.insertvalue
+; CHECK-DAG: llvm.return
 @str0 = private unnamed_addr constant [5 x i8] c"aaaa\00"
 @str1 = private unnamed_addr constant [5 x i8] c"bbbb\00"
 @g = global [2 x %my_struct] [%my_struct {i32 8, ptr getelementptr ([5 x i8], ptr @str0, i32 0, i32 1)}, %my_struct {i32 7, ptr getelementptr ([5 x i8], ptr @str1, i32 2, i32 3)}]


        


More information about the Mlir-commits mailing list