From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 9233C3858C2F for ; Sat, 2 Jul 2022 07:39:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9233C3858C2F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from [10.20.4.52] (unknown [10.20.4.52]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxr+M79r9iTRQDAA--.9771S2; Sat, 02 Jul 2022 15:39:40 +0800 (CST) Subject: Re: [PATCH] loongarch: use -mno-check-zero-division as the default for optimized code To: Xi Ruoyao Cc: Richard Biener , GCC Patches , Chenghua Xu , Weining Lu , Wang Xuerui References: From: Lulu Cheng Message-ID: <03929777-80a0-dcc1-3e04-9811583eebd3@loongson.cn> Date: Sat, 2 Jul 2022 15:39:39 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: AQAAf9Dxr+M79r9iTRQDAA--.9771S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww4fWr1kWrWrtw4Duw4UArb_yoW5Jr13pF y8Aw13ta1xtrnFgws7JwnxZF1Fywn3Gry7uF1S9ryxAa4qgF15Za40kFZ8u3Zru398WFy2 vFWFgF1fXa1jk37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvv14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr 1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcVAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCYjI0SjxkI62AI1cAE 67vIY487MxkIecxEwVCm-wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8Jw C20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAF wI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjx v20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73Uj IFyTuYvjfU5WlkUUUUU X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sat, 02 Jul 2022 07:39:51 -0000 在 2022/6/30 下午2:55, Richard Biener 写道: > On Thu, Jun 30, 2022 at 5:00 AM Xi Ruoyao via Gcc-patches > wrote: >> Hi, >> >> We've made a consensus [1] that not to enable trapping for division by >> zero by default for LLVM, and we think GCC should behave similarly. >> >> The main rationales: >> >> 1. Division by zero is undefined behavior, so in theory any portable >> program shall not depend on it. >> 2. There are already many targets where both the hardware and GCC port >> do nothing to trap on division by zero. A list taken from >> gcc.c-torture/execute/20101011-1.c: PowerPC, RISC-V, ARM64, MSP430, and >> many others. So in practice any portable program cannot depend on this >> trap. >> 3. As an ICPC assistant coach, I'm well aware that the main disadvantage >> not to trap on division by zero is "it breaks expectations of newbies". >> So, we keep -mcheck-zero-division defaulted for -O0 and -Og. For other >> optimization levels, it's well known that UBs are already breaking >> newbies' expectations [2]. >> 4. GCC is going to optimize more heavily exploiting integer division by >> zero [3]. So let's stop encouraging people to rely on any integer >> division by zero behavior from now. >> >> [1]: https://reviews.llvm.org/D128572/new/#3612039 >> [2]: http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html >> [3]: https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595099.html >> >> Patch content following. Bootstrapped and regtested on loongarch64- >> linux-gnu. Ok for trunk? > It might be worth backporting this behavioral change to the GCC 12 branch > as well (so 12.1 is the only release with different default behavior) and > documenting the change in changes.html diff --git a/gcc/common/config/loongarch/loongarch-common.cc b/gcc/common/config/loongarch/loongarch-common.cc index b6cbd84b873..f8b4660fabf 100644 --- a/gcc/common/config/loongarch/loongarch-common.cc +++ b/gcc/common/config/loongarch/loongarch-common.cc @@ -38,7 +38,4 @@ static const struct default_options loongarch_option_optimization_table[] =    { OPT_LEVELS_NONE, 0, NULL, 0 }  }; -#undef TARGET_DEFAULT_TARGET_FLAGS -#define TARGET_DEFAULT_TARGET_FLAGS    MASK_CHECK_ZERO_DIV - I think this modifications are needed, and there is no problem with the rest. Thanks! Lulu Cheng