[llvm] 5816d2a - [SimplifyCFG] Add tests for sinking load/store with swifterror operand.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 16 06:51:48 PDT 2023


Author: Florian Hahn
Date: 2023-08-16T14:51:29+01:00
New Revision: 5816d2ab287ab9d2e1624852946973ed43a0e3f2

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

LOG: [SimplifyCFG] Add tests for sinking load/store with swifterror operand.

Add test coverage for sinking/hoisting loads/stores with swifterror
pointers. Currently this isn't handled correctly by SimplifyCFG and
causes a verifier error.

Added: 
    llvm/test/Transforms/SimplifyCFG/hoist-sink-swifterror-store.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/SimplifyCFG/hoist-sink-swifterror-store.ll b/llvm/test/Transforms/SimplifyCFG/hoist-sink-swifterror-store.ll
new file mode 100644
index 00000000000000..213c04d54e9590
--- /dev/null
+++ b/llvm/test/Transforms/SimplifyCFG/hoist-sink-swifterror-store.ll
@@ -0,0 +1,85 @@
+; RUN: opt -passes='simplifycfg<sink-common-insts;hoist-common-insts>,verify' -disable-output %s
+
+; XFAIL: *
+
+declare void @clobber1()
+declare void @clobber2()
+
+; FIXME: currently simplifycfg tries to sink the stores to the exit block and
+; introduces a select for the pointer operand. This is not allowed for
+; swifterror pointers.
+define swiftcc void @sink_store(ptr %arg, ptr swifterror %arg1, i1 %c) {
+bb:
+  br i1 %c, label %then, label %else
+
+then:
+  call void @clobber1()
+  store ptr null, ptr %arg, align 8
+  br label %exit
+
+else:
+  call void @clobber2()
+  store ptr null, ptr %arg1, align 8
+  br label %exit
+
+exit:
+  ret void
+}
+
+define swiftcc void @hoist_store(ptr %arg, ptr swifterror %arg1, i1 %c) {
+bb:
+  br i1 %c, label %then, label %else
+
+then:
+  store ptr null, ptr %arg, align 8
+  call void @clobber1()
+  br label %exit
+
+else:
+  store ptr null, ptr %arg1, align 8
+  call void @clobber2()
+  br label %exit
+
+exit:
+  ret void
+}
+
+; FIXME: currently simplifycfg tries to sink the load to the exit block and
+; introduces a select for the pointer operand. This is not allowed for
+; swifterror pointers.
+define swiftcc ptr @sink_load(ptr %arg, ptr swifterror %arg1, i1 %c) {
+bb:
+  br i1 %c, label %then, label %else
+
+then:
+  call void @clobber1()
+  %l1 = load ptr, ptr %arg, align 8
+  br label %exit
+
+else:
+  call void @clobber2()
+  %l2 = load ptr, ptr %arg1, align 8
+  br label %exit
+
+exit:
+  %p = phi ptr [ %l1, %then ], [ %l2, %else ]
+  ret ptr %p
+}
+define swiftcc ptr @hoist_load(ptr %arg, ptr swifterror %arg1, i1 %c) {
+bb:
+  br i1 %c, label %then, label %else
+
+then:
+  %l1 = load ptr, ptr %arg, align 8
+  call void @clobber1()
+  br label %exit
+
+else:
+  %l2 = load ptr, ptr %arg1, align 8
+  call void @clobber2()
+  br label %exit
+
+exit:
+  %p = phi ptr [ %l1, %then ], [ %l2, %else ]
+  ret ptr %p
+}


        


More information about the llvm-commits mailing list