[Mlir-commits] [mlir] d67901d - [mlir][llvm] Use cached constants when importing landingpad instructions

Victor Perez llvmlistbot at llvm.org
Wed Apr 26 06:32:30 PDT 2023


Author: Victor Perez
Date: 2023-04-26T14:32:04+01:00
New Revision: d67901dd2df4b45389031d701eb3358017c218e8

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

LOG: [mlir][llvm] Use cached constants when importing landingpad instructions

Not using cached constants when importing instructions may lead to
undesired results, as breaking dominance rules in the translated MLIR
module.

Signed-off-by: Victor Perez <victor.perez at codeplay.com>

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

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/ModuleImport.cpp
    mlir/test/Target/LLVMIR/Import/exception.ll

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 4338f0314cdd8..64d4843f06388 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -1273,7 +1273,7 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
     SmallVector<Value> operands;
     operands.reserve(lpInst->getNumClauses());
     for (auto i : llvm::seq<unsigned>(0, lpInst->getNumClauses())) {
-      FailureOr<Value> operand = convertConstantExpr(lpInst->getClause(i));
+      FailureOr<Value> operand = convertValue(lpInst->getClause(i));
       if (failed(operand))
         return failure();
       operands.push_back(*operand);

diff  --git a/mlir/test/Target/LLVMIR/Import/exception.ll b/mlir/test/Target/LLVMIR/Import/exception.ll
index 374f51e06e840..944e5de6badd9 100644
--- a/mlir/test/Target/LLVMIR/Import/exception.ll
+++ b/mlir/test/Target/LLVMIR/Import/exception.ll
@@ -103,3 +103,38 @@ bb1:
   ; CHECK: llvm.resume %[[lp]] : i32
   resume i32 %resume
 }
+
+declare void @f0(ptr)
+declare void @f1(i32)
+declare void @f2({ptr, i32})
+
+; CHECK-LABEL: @landingpad_dominance
+define void @landingpad_dominance() personality ptr @__gxx_personality_v0 {
+entry:
+  ; CHECK:    %[[null:.*]] = llvm.mlir.null : !llvm.ptr
+  ; CHECK:    %[[c1:.*]] = llvm.mlir.constant(0 : i32) : i32
+  ; CHECK:    %[[undef:.*]] = llvm.mlir.undef : !llvm.struct<(ptr, i32)>
+  ; CHECK:    %[[tmpstruct:.*]] = llvm.insertvalue %[[null]], %[[undef]][0] : !llvm.struct<(ptr, i32)>
+  ; CHECK:    %[[struct:.*]] = llvm.insertvalue %[[c1]], %[[tmpstruct]][1] : !llvm.struct<(ptr, i32)>
+  ; CHECK:    llvm.call @f0(%[[null]]) : (!llvm.ptr) -> ()
+  call void @f0(ptr null)
+  ; CHECK:    llvm.call @f1(%[[c1]]) : (i32) -> ()
+  call void @f1(i32 0)
+  ; CHECK:    llvm.invoke @f0(%[[null]]) to ^[[block2:.*]] unwind ^[[block1:.*]] : (!llvm.ptr) -> ()
+  invoke void @f0(ptr null)
+      to label %exit unwind label %catch
+
+; CHECK:  ^[[block1]]:
+catch:
+  ; CHECK:    %[[lp:.*]] = llvm.landingpad (catch %[[null]] : !llvm.ptr) : !llvm.struct<(ptr, i32)>
+  %lp = landingpad { ptr, i32 } catch ptr null
+  ; CHECK:    llvm.call @f2(%[[struct]]) : (!llvm.struct<(ptr, i32)>) -> ()
+  call void @f2({ptr, i32} {ptr null, i32 0})
+  ; CHECK:    llvm.resume %[[lp]] : !llvm.struct<(ptr, i32)>
+  resume {ptr, i32} %lp
+
+; CHECK:  ^[[block2]]:
+exit:
+  ; CHECK:    llvm.return
+  ret void
+}


        


More information about the Mlir-commits mailing list