diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -526,7 +526,7 @@
 
 static bool useFramePointerForTargetByDefault(const ArgList &Args,
                                               const llvm::Triple &Triple) {
-  if (Args.hasArg(options::OPT_pg))
+  if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
     return true;
 
   switch (Triple.getArch()) {
@@ -6150,7 +6150,8 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
-    if (FPKeepKind == CodeGenOptions::FramePointerKind::None)
+    if (FPKeepKind == CodeGenOptions::FramePointerKind::None &&
+        !Args.hasArg(options::OPT_mfentry))
       D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
                                                       << A->getAsString(Args);
 
diff --git a/clang/test/Driver/mfentry.c b/clang/test/Driver/mfentry.c
--- a/clang/test/Driver/mfentry.c
+++ b/clang/test/Driver/mfentry.c
@@ -1,9 +1,16 @@
 // RUN: %clang -target s390x -c -### %s -mfentry 2>&1 | FileCheck %s
 // RUN: %clang -target i386 -c -### %s -mfentry 2>&1 | FileCheck %s
 // RUN: %clang -target x86_64 -c -### %s -mfentry 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-gnu-linux -pg -mfentry -O0 -### -E -o - %s 2>&1 | FileCheck -check-prefix=FP --implicit-check-not='"-mframe-pointer=none"' %s
+// RUN: %clang -target x86_64-gnu-linux -pg -mfentry -O2 -fno-omit-frame-pointer -### -E -o - %s 2>&1 | FileCheck -check-prefix=FP --implicit-check-not='"-mframe-pointer=none"' %s
+// RUN: %clang -target x86_64-gnu-linux -pg -mfentry -O2 -### -E -o - %s 2>&1 | FileCheck -check-prefix=NOFP --implicit-check-not='"-mframe-pointer=all"' %s
 
 // CHECK: "-mfentry"
 
 // RUN: %clang -target powerpc64le -c -### %s -mfentry 2>&1 | FileCheck --check-prefix=ERR %s
 
 // ERR: error: unsupported option '-mfentry' for target 'powerpc64le'
+
+// FP: "-mframe-pointer=all"
+// NOFP: "-mframe-pointer=none"
+void foo(void) {}