From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 9B8013858D1E for ; Sat, 24 Sep 2022 20:44:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B8013858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x430.google.com with SMTP id b23so3177060pfp.9 for ; Sat, 24 Sep 2022 13:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=xQ4VGP26TOYzUZsKUakv2MUbu2dYx7vLULvLxFvXOLg=; b=pRbJLT7sfixSFa5jR3CJ3EJ7f4QZhjbjDSULNqOmpjSU+D54vT6KjP79hwpZWe/Gd/ NIuq3UOzt+E+9wmqrwOxXVsfcZRfRFuVKi9zuNta21Cio7CPOr+8RiOC8yKwoVuXQNSG nAslxEAtDono1/Aa++7oHaVzQtd/sPlDt+gv2+tRICoq02gaDZEru+AZUKCI5RVq02o7 u/65NqtaXj2SGq43d8SXzBksQpvOXK1OaeNi58pYD5CgEekQ29e4P4VhBbAeg/2xpMk+ Q+HiRBTMPCCgwo+yh66Zf1hRcoSF6Nc1e/jVCQb/YRkcCLMuy1Q69jgNzjgVD4QVk+3a uy1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=xQ4VGP26TOYzUZsKUakv2MUbu2dYx7vLULvLxFvXOLg=; b=Ej5GJjNPxbiAX4CB+LSXY52R+6arZarnwIpT8KkQU50l59U2N5J+asQyOTci+SSvae f5oMviHfP5k4YAU4jQYHvPEwUrkOrRB+d9OYM4FYumsOpHv3LNEl3o1zJT1umYlyf850 aRipwP2CBqegsUt9r91rVtTyZ/UlOYHbXQ4eYnp7M7jcb1niY1rtIjPyNimDNu8GmeNw Zdmqy4FOMRTDxn0tb9TCWfKvEeJlJTT2HG/NZaNsi1FGNqs6knmRw9MnrSKs906WlXd2 bxKQAwuH11VuNxrIBTqKTnrIdx28eANR0ECmFY/lNs4Sjq8M9mTy3NYv2SfuLHadrrKE pMWg== X-Gm-Message-State: ACrzQf1EkYAhj44MNnuLmLZ7RceQlGrNjKeW9iJIA8VE3PTAW0wUG944 fM4xubvt78J67CUJ1Uo6OV4= X-Google-Smtp-Source: AMsMyM6/eQDXLvtbdxnHwneZWGZKHhkJHLshdtpB+i1bT/yXgqv+fXimMJ/rpYOqTTMCfwQuukNs9w== X-Received: by 2002:a05:6a00:1412:b0:557:d887:2025 with SMTP id l18-20020a056a00141200b00557d8872025mr2250880pfu.39.1664052248515; Sat, 24 Sep 2022 13:44:08 -0700 (PDT) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b0017305e99f00sm8188141plb.107.2022.09.24.13.44.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 24 Sep 2022 13:44:07 -0700 (PDT) Message-ID: Date: Sat, 24 Sep 2022 14:44:06 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH]middle-end fix floating out of constants in conditionals Content-Language: en-US To: Tamar Christina , gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 List-Id: On 9/23/22 03:21, Tamar Christina wrote: > Hi All, > > The following testcase: > > int zoo1 (int a, int b, int c, int d) > { > return (a > b ? c : d) & 1; > } > > gets de-optimized by the front-end since somewhere around GCC 4.x due to a fix > that was added to fold_binary_op_with_conditional_arg. > > The folding is supposed to succeed only if we have folded at least one of the > branches, however the check doesn't tests that all of the values are > non-constant. So if one of the operators are a constant it accepts the folding. > > This ends up folding > > return (a > b ? c : d) & 1; > > into > > return (a > b ? c & 1 : d & 1); > > and thus performing the AND twice. > > change changes it to reject the folding if one of the arguments are a constant > and if the operations being performed are the same. > > Secondly it adds a new match.pd rule to now also fold the opposite direction, so > it now also folds: > > return (a > b ? c & 1 : d & 1); > > into > > return (a > b ? c : d) & 1; > > Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu > and issues. > > Ok for master? > > Thanks, > Tamar > > gcc/ChangeLog: > > * fold-const.cc (fold_binary_op_with_conditional_arg): Add relaxation. > * match.pd: Add ternary constant fold rule. > * tree-cfg.cc (verify_gimple_assign_ternary): RHS1 of a COND_EXPR isn't > a value but an expression itself. > > gcc/testsuite/ChangeLog: > > * gcc.target/aarch64/if-compare_3.c: New test. OK jeff