diff --git a/interpreter/cling/lib/Interpreter/CIFactory.cpp b/interpreter/cling/lib/Interpreter/CIFactory.cpp
index ad1cc34de777fdf0db864560fbfb04d96594c87e..bc6e7c0abe8f0ccd1c3e196dd4b73d75ba2dc899 100644
--- a/interpreter/cling/lib/Interpreter/CIFactory.cpp
+++ b/interpreter/cling/lib/Interpreter/CIFactory.cpp
@@ -1197,6 +1197,7 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
     CGOpts.UnrollLoops = 1;
     CGOpts.VectorizeLoop = 1;
     CGOpts.VectorizeSLP = 1;
+    CGOpts.DisableO0ImplyOptNone = 1; // Enable dynamic opt level switching.
 
     CGOpts.setInlining((CGOpts.OptimizationLevel == 0)
                        ? CodeGenOptions::OnlyAlwaysInlining