From patchwork Tue Mar 28 13:11:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 76069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2205258vqo; Tue, 28 Mar 2023 06:12:04 -0700 (PDT) X-Google-Smtp-Source: AKy350ZlNTa7ZVApyKmnP5dUZQu3cLLxeTQ+k9RYZj4AYzqNk0sJRBLvOqQyniUl4xL/z0GHY3hV X-Received: by 2002:a17:906:4f0b:b0:931:59f:d42 with SMTP id t11-20020a1709064f0b00b00931059f0d42mr16935414eju.29.1680009124638; Tue, 28 Mar 2023 06:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680009124; cv=none; d=google.com; s=arc-20160816; b=u+zh9B41jlfkIzAHOZq8QIZoaq8+fGES9DA4f2EVRNUuP8lujRSH0z8Z4sKMt6JZdF ELjrohYD2sG4M7vQ/nQL7EQqSMbAOeHOT3lQ/3zQkEtLw6g7cdoXpNyRpp0WyV2PiShM 7vIm7BG0GApEnQnQIFTicNy7KEcuOehKxYn5B7/bSeFJwhJCJ6hJN7eqrjigYZpvvRM+ pR1M633aO2sCqPIBh1qkMOUYqJVZs9NqGz32wsiUYsBpObNUsC+OM51Cq/pFrMQoVwHq iooFRuyhKE+YPa2VRTy8P5HhVtJj9gveVdGARNfythcwnoiXrGtsvCFu7VBUtiXb/5X3 P3TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dkim-filter:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=yJ/u6gJ+nCWzB4WVOmmkO2CERvTk4TEGvhX8aUXSxJs=; b=r3MkoDVOgD1BLmPT/bM8pyRNUO11/LbCb0LVSv5IKTQJUvk7eNUeELaOtEUwR9Q8TN Gl5+jNG2H9Cvd+8wbKw0cPFDICyQqhWE7ICnpwTQ0Ss5rU0YXCOF9cJZE57Cr2KBcs7t PuNPJeMtD5XS/g0ZOV7n20/7bW2pe9EuxILCc5VowVb2+RdEplHMstkMtQl9nErhXKhS d4LYP9EWza7xTOvkynJ8UZNQ7MkV1iETJ8ZYFX5GP/QLeylYLwD4iW7Sy3uuMlFCEdqN AxCAZDhbwt5CiqXiB75aWZd9nPGf83wGkxe6Ew/xRTfBzXDbGhYz1hADE1c62uUS9RzH CZ/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VJ0C7xvS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a18-20020a170906191200b008df5a5088bcsi20027308eje.123.2023.03.28.06.12.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 06:12:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VJ0C7xvS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D5DB93858425 for ; Tue, 28 Mar 2023 13:12:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5DB93858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680009122; bh=yJ/u6gJ+nCWzB4WVOmmkO2CERvTk4TEGvhX8aUXSxJs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=VJ0C7xvSJp/aRXaBeZ/vgLyNRW6yILW8Xsh+qzZv8E/K+4MgoGo1Eir+PWnYbsJJx JMtowjFBRowwKYuMDW/3/Q+ogHvp0BHDHmVx6RE3VuJwzUQE8qrsRtsNwZ5yZ6X8Yu vdb4UxJ6284gqagblYk5YUOwl+dabUDMu9NGKD+U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 66489385842E for ; Tue, 28 Mar 2023 13:11:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66489385842E Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 0DDD340D4004; Tue, 28 Mar 2023 13:11:16 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 0DDD340D4004 To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH] haifa-sched: fix autopref_rank_for_schedule comparator [PR109187] Date: Tue, 28 Mar 2023 16:11:10 +0300 Message-Id: <20230328131110.7780-1-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761617248091461734?= X-GMAIL-MSGID: =?utf-8?q?1761617248091461734?= Do not attempt to use a plain subtraction for generating a three-way comparison result in autopref_rank_for_schedule qsort comparator, as offsets are not restricted and subtraction may overflow. Open-code a safe three-way comparison instead. gcc/ChangeLog: PR rtl-optimization/109187 * haifa-sched.cc (autopref_rank_for_schedule): Avoid use of overflowing subtraction in three-way comparison. gcc/testsuite/ChangeLog: PR rtl-optimization/109187 * gcc.dg/pr109187.c: New test. --- I think I can commit this as obvious if no comment in a day, but explicit ack is always appreciated. Alexander gcc/haifa-sched.cc | 2 +- gcc/testsuite/gcc.dg/pr109187.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr109187.c diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc index 4efaa9445..e11cc5c35 100644 --- a/gcc/haifa-sched.cc +++ b/gcc/haifa-sched.cc @@ -5686,7 +5686,7 @@ autopref_rank_for_schedule (const rtx_insn *insn1, const rtx_insn *insn2) if (!irrel1 && !irrel2) /* Sort memory references from lowest offset to the largest. */ - r = data1->offset - data2->offset; + r = (data1->offset > data2->offset) - (data1->offset < data2->offset); else if (write) /* Schedule "irrelevant" insns before memory stores to resolve as many producer dependencies of stores as possible. */ diff --git a/gcc/testsuite/gcc.dg/pr109187.c b/gcc/testsuite/gcc.dg/pr109187.c new file mode 100644 index 000000000..1ef14a73d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109187.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 --param sched-autopref-queue-depth=1" } */ + +void f(int *a) +{ + for (;;) + asm("" :: "r"(a[-0x10000000]), "r"(a[0x10000000]), "r"(a[0]) : "memory"); +}