From 0b274ed499603d30694c0b995252ab014609acf9 Mon Sep 17 00:00:00 2001 From: Steven Wan Date: Wed, 3 Mar 2021 19:06:37 -0500 Subject: [PATCH] [AIX] Update default arch on AIX On AIX, the default arch level should match the minimum supported arch level of the OS version. Differential Revision: https://reviews.llvm.org/D97823 --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 11 ++++++++--- clang/test/Driver/aix-mcpu-default.c | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 9471639350af..46a0fc67ced0 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -399,9 +399,14 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T, if (!TargetCPUName.empty()) return TargetCPUName; - if (T.isOSAIX()) - TargetCPUName = "pwr4"; - else if (T.getArch() == llvm::Triple::ppc64le) + if (T.isOSAIX()) { + unsigned major, minor, unused_micro; + T.getOSVersion(major, minor, unused_micro); + // The minimal arch level moved from pwr4 for AIX7.1 to + // pwr7 for AIX7.2. + TargetCPUName = + (major < 7 || (major == 7 && minor < 2)) ? "pwr4" : "pwr7"; + } else if (T.getArch() == llvm::Triple::ppc64le) TargetCPUName = "ppc64le"; else if (T.getArch() == llvm::Triple::ppc64) TargetCPUName = "ppc64"; diff --git a/clang/test/Driver/aix-mcpu-default.c b/clang/test/Driver/aix-mcpu-default.c index 10636abad304..7b55839a8066 100644 --- a/clang/test/Driver/aix-mcpu-default.c +++ b/clang/test/Driver/aix-mcpu-default.c @@ -1,10 +1,18 @@ -// Check that the target cpu defaults to power4 on AIX. +// Check that the target cpu defaults to power7 on AIX7.2 and up. // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ -// RUN: -target powerpc-ibm-aix \ -// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT %s -// CHECK-MCPU-DEFAULT-NOT: warning: -// CHECK-MCPU-DEFAULT: {{.*}}clang{{.*}}" "-cc1" -// CHECK-MCPU-DEFAULT: "-target-cpu" "pwr4" +// RUN: -target powerpc-ibm-aix7.2 \ +// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s +// CHECK-MCPU-DEFAULT-AIX72-NOT: warning: +// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1" +// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7" + +// Check that the target cpu defaults to power4 on AIX7.1 and below. +// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ +// RUN: -target powerpc-ibm-aix7.1 \ +// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s +// CHECK-MCPU-DEFAULT-AIX71-NOT: warning: +// CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1" +// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4" // Check that the user is able to overwrite the default with '-mcpu'. // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \