diff --git a/testsuite/tests/simplCore/should_run/T19413.hs b/testsuite/tests/simplCore/should_run/T19413.hs
new file mode 100644
index 0000000000000000000000000000000000000000..65727e4e76f13b7673a48000d1d9ccf920a8b834
--- /dev/null
+++ b/testsuite/tests/simplCore/should_run/T19413.hs
@@ -0,0 +1,17 @@
+{-# OPTIONS_GHC -O1 #-}
+
+import System.IO.Unsafe
+import Data.IORef
+
+{-# NOINLINE resourceId #-}
+resourceId :: IO Int
+resourceId = unsafePerformIO counter
+
+counter :: IO (IO Int)
+counter = do
+    ref <- newIORef 0
+    pure $ atomicModifyIORef' ref $ \i -> let j = i + 1 in (j, j)
+
+main = do
+    print =<< resourceId
+    print =<< resourceId
diff --git a/testsuite/tests/simplCore/should_run/T19413.stdout b/testsuite/tests/simplCore/should_run/T19413.stdout
new file mode 100644
index 0000000000000000000000000000000000000000..1191247b6d9a206f6ba3d8ac79e26d041dd86941
--- /dev/null
+++ b/testsuite/tests/simplCore/should_run/T19413.stdout
@@ -0,0 +1,2 @@
+1
+2
diff --git a/testsuite/tests/simplCore/should_run/all.T b/testsuite/tests/simplCore/should_run/all.T
index afedee6bcc62b7b5726d05d83679d74309bdcdeb..a6458ee31148678ce10c5cf39a2e4cb858c9938e 100644
--- a/testsuite/tests/simplCore/should_run/all.T
+++ b/testsuite/tests/simplCore/should_run/all.T
@@ -97,3 +97,4 @@ test('NumConstantFolding8', normal, compile_and_run, [''])
 test('NumConstantFolding16', normal, compile_and_run, [''])
 test('NumConstantFolding32', normal, compile_and_run, [''])
 test('NumConstantFolding', normal, compile_and_run, [''])
+test('T19413', normal, compile_and_run, [''])