From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id A2D8038708BC for ; Thu, 27 Aug 2020 13:27:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A2D8038708BC Received: by mail-wm1-x330.google.com with SMTP id y8so3742092wma.0 for ; Thu, 27 Aug 2020 06:27:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=5fl001/pUwPWEy5tLNS/UttnocrbiO0aNEJ5mxUzIuo=; b=IhcUoHkklltwy1ssi4uoNtut47qqH/UzDZPrxbol3uWXfY5VAdQGvxB3vjKANUJISS eXKiIIEI1+BhddS1qYWrdw8tH/g0HURNVzNij7H1J8s3MVxSv1fWRjFwuqeqnbcs5ocz 4kN1zwbyWh849os6lHEpolsYd2RPJfqC+tBQrI2S/KSMrbUoGNTQu3XFfdMSveT80jCV Cs7+q0B2z5Ebjh8ljRFZcPzOBMAm8iK8TyxFVCBlIBKwu0QUORz1hkP/KkYFLp7bOTMT PpeNgBqipKVJ4BAOS9qUK3i+sCpsXc8ToT/qAVZF8W2AwobimzyYTjBWRALIeYV0/kF6 amDw== X-Gm-Message-State: AOAM531db15H3soNH58y2nQ2AuqHufj6X2yLjZ1ZhKVNh0xOKO2Lgc/5 +A4a3epXVBXc2VkLm2SToDwIXMEJROAfHQ== X-Google-Smtp-Source: ABdhPJwWPvGRJKXtNlbOrF3eyroziT9uPi5ggUNtbnETr99TdnCKuYKjSzOu246USkQWx7WwhsR6aA== X-Received: by 2002:a1c:5f06:: with SMTP id t6mr11825604wmb.54.1598534848863; Thu, 27 Aug 2020 06:27:28 -0700 (PDT) Received: from localhost.localdomain (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id g3sm5785167wrb.59.2020.08.27.06.27.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Aug 2020 06:27:28 -0700 (PDT) From: Christophe Lyon To: gcc-patches@gcc.gnu.org Subject: [PATCH] arm: Fix switch tables for thumb-1 with -mpure-code [PR96768] Date: Thu, 27 Aug 2020 13:27:27 +0000 Message-Id: <1598534847-8544-1-git-send-email-christophe.lyon@linaro.org> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-15.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Aug 2020 13:27:32 -0000 In comment 14 from PR94538, it was suggested to switch off jump tables on thumb-1 cores when using -mpure-code, like we already do for thumb-2. This is what this patch does, and also restores the previous value of CASE_VECTOR_PC_RELATIVE since it was not the right way of handling this. It also adds a new test, since the existing no-casesi.c did not catch this problem. Tested by running the whole testsuite with -mpure-code -mcpu=cortex-m0 -mfloat-abi=soft, no regression and the new test passes (and fails without the fix). 2020-08-27 Christophe Lyon gcc/ * config/arm/arm.h (CASE_VECTOR_PC_RELATIVE): Remove condition on -mpure-code. * config/arm/thumb1.md (tablejump): Disable when -mpure-code. gcc/testsuite/ * gcc.target/arm/pure-code/pr96768.c: New test. --- gcc/config/arm/arm.h | 5 ++--- gcc/config/arm/thumb1.md | 2 +- gcc/testsuite/gcc.target/arm/pure-code/pr96768.c | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/arm/pure-code/pr96768.c diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index 3887c51..7d43721 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -1975,10 +1975,9 @@ enum arm_auto_incmodes for the index in the tablejump instruction. */ #define CASE_VECTOR_MODE Pmode -#define CASE_VECTOR_PC_RELATIVE ((TARGET_THUMB2 \ +#define CASE_VECTOR_PC_RELATIVE (TARGET_THUMB2 \ || (TARGET_THUMB1 \ - && (optimize_size || flag_pic))) \ - && (!target_pure_code)) + && (optimize_size || flag_pic))) #define CASE_VECTOR_SHORTEN_MODE(min, max, body) \ diff --git a/gcc/config/arm/thumb1.md b/gcc/config/arm/thumb1.md index f0129db..602039e 100644 --- a/gcc/config/arm/thumb1.md +++ b/gcc/config/arm/thumb1.md @@ -2012,7 +2012,7 @@ (define_insn "*epilogue_insns" (define_expand "tablejump" [(parallel [(set (pc) (match_operand:SI 0 "register_operand")) (use (label_ref (match_operand 1 "" "")))])] - "TARGET_THUMB1" + "TARGET_THUMB1 && !target_pure_code" " if (flag_pic) { diff --git a/gcc/testsuite/gcc.target/arm/pure-code/pr96768.c b/gcc/testsuite/gcc.target/arm/pure-code/pr96768.c new file mode 100644 index 0000000..fd4cad5 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pure-code/pr96768.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-mpure-code" } */ + +int f2 (int x, int y) +{ + switch (x) + { + case 0: return y + 0; + case 1: return y + 1; + case 2: return y + 2; + case 3: return y + 3; + case 4: return y + 4; + case 5: return y + 5; + } + return y; +} + +/* We do not want any load from literal pool, but accept loads from r7 + (frame pointer, used at -O0). */ +/* { dg-final { scan-assembler-not "ldr\tr\\d+, \\\[r\[0-689\]+\\\]" } } */ +/* { dg-final { scan-assembler "text,\"0x20000006\"" } } */ -- 2.7.4