[llvm] 200f341 - [reg2mem] Skip non-sized Instructions (PR58890)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 03:47:51 PST 2022


Author: HanSheng Zhang
Date: 2022-11-14T12:47:39+01:00
New Revision: 200f3410cd0136460a776001712239129df7dd35

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

LOG: [reg2mem] Skip non-sized Instructions (PR58890)

We can only convert sized values into alloca/load/store, skip
instructions returning other types.

Fixes https://github.com/llvm/llvm-project/issues/58890.

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

Added: 
    llvm/test/Transforms/Reg2Mem/catchswitch-crash.ll
    llvm/test/Transforms/Reg2Mem/non-token-test.ll

Modified: 
    llvm/lib/Transforms/Scalar/Reg2Mem.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/Reg2Mem.cpp b/llvm/lib/Transforms/Scalar/Reg2Mem.cpp
index 9dc64493a9ee7..db7a1f24660c9 100644
--- a/llvm/lib/Transforms/Scalar/Reg2Mem.cpp
+++ b/llvm/lib/Transforms/Scalar/Reg2Mem.cpp
@@ -40,6 +40,9 @@ STATISTIC(NumRegsDemoted, "Number of registers demoted");
 STATISTIC(NumPhisDemoted, "Number of phi-nodes demoted");
 
 static bool valueEscapes(const Instruction &Inst) {
+  if (!Inst.getType()->isSized())
+    return false;
+
   const BasicBlock *BB = Inst.getParent();
   for (const User *U : Inst.users()) {
     const Instruction *UI = cast<Instruction>(U);

diff  --git a/llvm/test/Transforms/Reg2Mem/catchswitch-crash.ll b/llvm/test/Transforms/Reg2Mem/catchswitch-crash.ll
new file mode 100644
index 0000000000000..9d2347dec4b31
--- /dev/null
+++ b/llvm/test/Transforms/Reg2Mem/catchswitch-crash.ll
@@ -0,0 +1,35 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=reg2mem -S < %s | FileCheck %s
+
+declare void @"read_mem"()
+
+define void @"memcpy_seh"() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
+; CHECK-LABEL: @memcpy_seh(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    %"reg2mem alloca point" = bitcast i32 0 to i32
+; CHECK-NEXT:    invoke void @read_mem()
+; CHECK-NEXT:    to label [[CLEANUP:%.*]] unwind label [[CATCH_DISPATCH:%.*]]
+; CHECK:       catch.dispatch:
+; CHECK-NEXT:    [[TMP0:%.*]] = catchswitch within none [label %__except] unwind to caller
+; CHECK:       __except:
+; CHECK-NEXT:    [[TMP1:%.*]] = catchpad within [[TMP0]] [i8* null]
+; CHECK-NEXT:    unreachable
+; CHECK:       cleanup:
+; CHECK-NEXT:    ret void
+;
+entry:
+  invoke void @"read_mem"()
+  to label %cleanup unwind label %catch.dispatch
+
+catch.dispatch:                                   ; preds = %entry
+  %0 = catchswitch within none [label %__except] unwind to caller
+
+__except:                                         ; preds = %catch.dispatch
+  %1 = catchpad within %0 [i8* null]
+  unreachable
+
+cleanup:                                          ; preds = %entry
+  ret void
+}
+
+declare i32 @__C_specific_handler(...)

diff  --git a/llvm/test/Transforms/Reg2Mem/non-token-test.ll b/llvm/test/Transforms/Reg2Mem/non-token-test.ll
new file mode 100644
index 0000000000000..e30f37abaa443
--- /dev/null
+++ b/llvm/test/Transforms/Reg2Mem/non-token-test.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=reg2mem -S < %s | FileCheck %s
+
+%opaque = type opaque
+
+declare %opaque @ret_opaque()
+declare void @pass_opaque(%opaque)
+
+define void @test() {
+; CHECK-LABEL: @test(
+; CHECK-NEXT:    %"reg2mem alloca point" = bitcast i32 0 to i32
+; CHECK-NEXT:    [[X:%.*]] = call [[OPAQUE:%.*]] @ret_opaque()
+; CHECK-NEXT:    br label [[NEXT:%.*]]
+; CHECK:       next:
+; CHECK-NEXT:    call void @pass_opaque([[OPAQUE]] [[X]])
+; CHECK-NEXT:    ret void
+;
+  %x = call %opaque @ret_opaque()
+  br label %next
+
+next:
+  call void @pass_opaque(%opaque %x)
+  ret void
+}


        


More information about the llvm-commits mailing list