From patchwork Tue Aug 23 01:06:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp739917wro; Mon, 22 Aug 2022 18:07:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ea8mGAExFPzQldcs+VfsovFW5ACfrZowDCh+bt6lwn38nagDRPImS8TjX+tzHXpjXXi1G X-Received: by 2002:a17:906:7c4a:b0:73d:9279:2c42 with SMTP id g10-20020a1709067c4a00b0073d92792c42mr2118069ejp.597.1661216838692; Mon, 22 Aug 2022 18:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661216838; cv=none; d=google.com; s=arc-20160816; b=p7ev6FZ2xjBSjdtE6cRpQa3RgwttmUWFy058HQ8jqNTQNiQ8KNstu75tESnTbxCX2g 9dFnS2rFsl10lxtxcA1VIxxXa5B5zCd16wMrUMKgR5mVLrHc4X6sFiZAEGAfGL75FIo4 V0/pzaHDIrIlg15ryxTSkpxzurDpeMYWJ82O0ZGNjrSEYl1kCMehL18X0MBHvbBzoeVB +QjkHDUAaDaEdEpveSLwzW3d8JZHC3XHVkYa7yqd03EYvtAH09fLq4jDwN/jC9ktzLpg 7CcnVy2VMMuzfTT2KvER9Cu/Oo6zZG6e+ddu8WL4e1vgrn9jpgIk6yay4vqX7ieY2q/P cfXQ== 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-language :subject:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=geEMt5fhZHng9sugM5/7D2Tlu6cF1EUII9j8dK+sim0=; b=gRYsH3PgrrOaNuf6J5MG0zgOnbOVmb7bgvUweY7Jf+IcBscCyWYbPOWMnKomcwXXkz QYRYWFgd6d5lOLptGSU8pVNwWOMcnmG1LZFud/UeoUWW80BC8UEULmTkrMRcsFkQlu95 aU9/LIO5cc/e8Rn6dhoSGZocZD7LG9uWEf/wh3YZ7knIr/k4/gjjt7OlIE8swXD9Dfrt 2YXnB+oDhl1Xemct1qVdtgPZX9yYDOC7xBWhYM5XQacEFI5UYaLLzVA94f9Sw3h9x5RN fjhnWXzFdKGMoJJ+TP5IwZ2DChdJ8DmSXWpFHwGG54cH+6QFnKv/lHAf4C+zx/waDMTh oRwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ArnQUOoA; 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 y23-20020a170906559700b0073d6d81733bsi5416158ejp.678.2022.08.22.18.07.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 18:07:18 -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=ArnQUOoA; 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 BAA80385E001 for ; Tue, 23 Aug 2022 01:07:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAA80385E001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661216830; bh=geEMt5fhZHng9sugM5/7D2Tlu6cF1EUII9j8dK+sim0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ArnQUOoAe7uiWl8FmbOZYE+cGKbQGVOjrcpmRGVzXZcaYBlr1t6N0mFjJGQQHo4vi jlEM1HVNQ2NmegexBXbtscf72P/StrGqUczT+7IjVED8ZnaxN68E3J4853NH+CEtvd G53Pc4Y9r1pR4EHQg2dnzpPGsPSxJAYWUvmelBF8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BE3C33857809 for ; Tue, 23 Aug 2022 01:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BE3C33857809 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-490-dBLeExa2NsOpinYyb51jvQ-1; Mon, 22 Aug 2022 21:06:22 -0400 X-MC-Unique: dBLeExa2NsOpinYyb51jvQ-1 Received: by mail-qv1-f71.google.com with SMTP id gh7-20020a05621429c700b00496b1a465b1so6450828qvb.5 for ; Mon, 22 Aug 2022 18:06:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=sdu8elJl1J1KxcPZkWbp2MtKesTpGPtOMU5NDxbf2d4=; b=WpSzuxrDGW8/NQZQm1pvFA0Ls+45IuJT75Nr87W31ihQbngP12pAGGmcPTdnyBt6Ew RWTqkib1TaJ/57Ae9j5HOGqARJNsfwyXI2LmMJ+CBn7nsqmYrMD0QjPW21Mbf3Tw6jiv XQxAiUUnBzGenuVFrSyC899Q5pY39cY9797ZyWbUl1wvidBHj/byhaEtG1u0dWMCeuJK 4hxxNfwOEhorZg6iZ7EgEQgcJn1IXxjjqUj2NlMtJw8ygckLKANasEsIP6RYtsps2GzY YykS8/4HPNNLFcoJ75FhvE+H9VMeQnSu3kPp3Q3OUMZUs5s423tkwI2HhrO0xOkBW5CC /BnQ== X-Gm-Message-State: ACgBeo0khXmYBTQI25WTBCrVphv18qdE26lVBIPAaQEYlVn8AZMMwLr9 iLgID7SXrP44mWuEZfnDDwK5RP4cSGKyf5igqAzFSOtwLVzjE5FmehWwA4idNORLq7y4szLoI1I 96oyg35wwDHfhuj5yE4GF9kV3ONhzXXQCcw3SQcNk08rdGO+lufRWfOXHtYEIFxyWi8pw+A== X-Received: by 2002:a05:622a:649:b0:343:7b74:5cd1 with SMTP id a9-20020a05622a064900b003437b745cd1mr17837077qtb.407.1661216782113; Mon, 22 Aug 2022 18:06:22 -0700 (PDT) X-Received: by 2002:a05:622a:649:b0:343:7b74:5cd1 with SMTP id a9-20020a05622a064900b003437b745cd1mr17837059qtb.407.1661216781822; Mon, 22 Aug 2022 18:06:21 -0700 (PDT) Received: from [192.168.0.135] ([192.24.49.145]) by smtp.gmail.com with ESMTPSA id v16-20020a05620a0f1000b006b97151d2b3sm12071851qkl.67.2022.08.22.18.06.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Aug 2022 18:06:21 -0700 (PDT) Message-ID: <9241ba5f-224f-3f36-78a8-3890f43711d7@redhat.com> Date: Mon, 22 Aug 2022 21:06:17 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: gcc-patches Subject: [COMMITTED] PR tree-optimization/106687 - Return the correct relation X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod 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?1741912107995140446?= X-GMAIL-MSGID: =?utf-8?q?1741912107995140446?= With an input condition of op1 > op2, and evaluating the unsigned expression:     LHS = op1 - op2 range-ops was returning LHS < op1 , which is incorrect as op2 could be zero.  This patch adjusts it to return LHS <= op1. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew commit de6d9e0b3d5c08896cbf047b299fc7f8d1e42be7 Author: Andrew MacLeod Date: Mon Aug 22 15:40:48 2022 -0400 Return the correct relation With an input condition of op1 > op2, and evaluating the unsigned expression: LHS = op1 - op2 range-ops was returning LHS < op1 , which is incorrect as op2 coould be zero. This patch adjusts it to return LHS <= op1. PR tree-optimization/106687 gcc/ * range-op.cc (operator_minus::lhs_op1_relation): Return VREL_LE for the VREL_GT case as well. gcc/testsuite/ * g++.dg/pr106687.C: New. diff --git a/gcc/range-op.cc b/gcc/range-op.cc index dfdd971c90a..806edf1012e 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1378,7 +1378,6 @@ operator_minus::lhs_op1_relation (const irange &, const irange &op1, switch (rel) { case VREL_GT: - return VREL_LT; case VREL_GE: return VREL_LE; default: diff --git a/gcc/testsuite/g++.dg/pr106687.C b/gcc/testsuite/g++.dg/pr106687.C new file mode 100644 index 00000000000..75ac81c216c --- /dev/null +++ b/gcc/testsuite/g++.dg/pr106687.C @@ -0,0 +1,22 @@ +// { dg-do run } +// { dg-options "-O2" } + +bool var_0 = (bool)0; +unsigned int var_7 = 42; +char var_215; + +int main() { + unsigned b = var_0; + unsigned p2 = var_7; + unsigned *tp; + if (b < p2) + tp = &p2; + else + tp = &b; + unsigned tt = *tp; + unsigned t = tt ^ (var_7 - var_0); + var_215 = t ? t : 42; + if (var_215 != 42) + __builtin_abort(); + return 0; +}