From patchwork Tue Jan 10 14:12:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 90707 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp1036246obz; Tue, 10 Jan 2017 06:13:06 -0800 (PST) X-Received: by 10.98.202.204 with SMTP id y73mr4067614pfk.51.1484057585975; Tue, 10 Jan 2017 06:13:05 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v10si2285562pgc.32.2017.01.10.06.13.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 06:13:05 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-445775-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-445775-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-445775-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=WJMLNzPrtjKcc5NPWX7y4wgVEgpXgai9j8LVreLEoP2mXejlfV 37kFcV76Ty6Qb3bf+1QsKkGCDo0hZzQ5PmywlJuvmbFR+i5l1JQn91Lho/NuOaux VQViGzaECSomniji0B0kWpdfa8ojgtdw025i0IZhrmnmUjddFg5Ex7YRU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=LW4fDLl/iOZ/b+apdqzSE5i2p3o=; b=ent4fsFW/K2cdMOsE39T IIsPnRl73BUxrb5jm5IsvyMwln7YiGvLYSe2XiLeN9aPr6+S0BlZNsggAgKrDE1a UG9jTR9ggP4nxTw2hdeIjjAv4KwRPij6sZ5SqwxbC6wcSW711kVrPA48hT50i4HF pWYkMm78+XSEL+sMgbNU4rQ= Received: (qmail 52963 invoked by alias); 10 Jan 2017 14:12:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 52953 invoked by uid 89); 10 Jan 2017 14:12:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=browsing, optimizer, Besides, Hx-spam-relays-external:sk:mail-yb X-HELO: mail-yb0-f194.google.com Received: from mail-yb0-f194.google.com (HELO mail-yb0-f194.google.com) (209.85.213.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jan 2017 14:12:42 +0000 Received: by mail-yb0-f194.google.com with SMTP id l23so2302119ybj.3 for ; Tue, 10 Jan 2017 06:12:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=D+oGC7+g5M3/OBT3ssmTs+HG+Cjggc8gOZMZoAdrbMI=; b=XnPwqoX0MsPddZMvjK4glsCtP1pl48aYovArLOT4c+Lz/8381Cq+YM35um6OIkH3fU 5CoLykRbpksbI+R5b4YPM37VUEBjdy4p4y0p/kAgB31utO43aI7nVJrAlqNxLEcVqqYQ f35FUjhfoBgbPd6D3a3UKrl5KwUa8FYp8zJeFbKuuz1hFOpdXjuFh7FZJNDzUmM5VVYf REMFUsh4bircwKzAF7aiRDf5/SgdDqhPIVPkTYuzaCIAqr4NjYZiIcl9mS29bnsuFmpS UBpA0A1c7vHOSh/9ZXR+/QxJM8e6HQwgshOvqQGcCsYTXDhryySCdKgD1XemV4qd8Wn1 lp2w== X-Gm-Message-State: AIkVDXJ52GmDpzat7nJcFA0BkJYbgATZY7QWd99jFHWHxfdXolVIng3x/eGIOEFx6adwdg== X-Received: by 10.37.66.17 with SMTP id p17mr307391yba.46.1484057560328; Tue, 10 Jan 2017 06:12:40 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::d:41ba]) by smtp.googlemail.com with ESMTPSA id d5sm948042ywf.20.2017.01.10.06.12.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 06:12:39 -0800 (PST) To: GCC Patches Cc: nicstange@gmail.com, segher@kernel.crashing.org From: Nathan Sidwell Subject: [PATCH] combine ignoring a check Message-ID: <7d95d644-006e-5533-ed9a-d476124a19ac@acm.org> Date: Tue, 10 Jan 2017 09:12:38 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 This patch addresses an issue Nicolai found while browsing combine.c. He noticed some checking code that looked like: for (i = 0; i < NUM_ARGS; i++) if (!cond) break; for (i = 0; i < NUM_ARGS; i++) if (!other_cond) break; if (i == NUM_ARGS) do_the_thing; the intent is that both cond and other_cond are true for all args, but the first loop's negative result (i != NUM_ARGS) is being ignored. This patch fixes that problem, and I took the opportunity to merge both loops into a single loop: ok = true; for (i = 0; ok && i < NUM_ARGS; i++) if (!cond || !other_cond) ok = false; if (ok) do_the_thing; Segher commented on IRC that a single loop would be slower. I disagree. These days the optimizer is smart enough to turn that boolean logic into direct control flow, and a single loop is certainly smaller code (I checked). The only case that might be faster would be an early out if the first loop resulted in a negative. But I doubt that's significant, particularly as the first loop's check is the more expensive one and the second loops check is very cheap. booted & tested on x86_64-linux. Thanks to Nic for finding this problem and helping test it. nathan -- Nathan Sidwell 2017-01-10 Nathan Sidwell Nicolai Stange * combine.c (try_combine): Don't ignore result of overlap checking loop. Combine overlap & asm check into single loop. Index: combine.c =================================================================== --- combine.c (revision 244226) +++ combine.c (working copy) @@ -2785,22 +2785,24 @@ try_combine (rtx_insn *i3, rtx_insn *i2, (Besides, reload can't handle output reloads for this.) The problem can also happen if the dest of I3 is a memory ref, - if another dest in I2 is an indirect memory ref. */ - for (i = 0; i < XVECLEN (p2, 0); i++) - if ((GET_CODE (XVECEXP (p2, 0, i)) == SET - || GET_CODE (XVECEXP (p2, 0, i)) == CLOBBER) - && reg_overlap_mentioned_p (SET_DEST (PATTERN (i3)), - SET_DEST (XVECEXP (p2, 0, i)))) - break; + if another dest in I2 is an indirect memory ref. - /* Make sure this PARALLEL is not an asm. We do not allow combining + Neither can this PARALLEL be not an asm. We do not allow combining that usually (see can_combine_p), so do not here either. */ - for (i = 0; i < XVECLEN (p2, 0); i++) - if (GET_CODE (XVECEXP (p2, 0, i)) == SET - && GET_CODE (SET_SRC (XVECEXP (p2, 0, i))) == ASM_OPERANDS) - break; + bool ok = true; + for (i = 0; ok && i < XVECLEN (p2, 0); i++) + { + if ((GET_CODE (XVECEXP (p2, 0, i)) == SET + || GET_CODE (XVECEXP (p2, 0, i)) == CLOBBER) + && reg_overlap_mentioned_p (SET_DEST (PATTERN (i3)), + SET_DEST (XVECEXP (p2, 0, i)))) + ok = false; + else if (GET_CODE (XVECEXP (p2, 0, i)) == SET + && GET_CODE (SET_SRC (XVECEXP (p2, 0, i))) == ASM_OPERANDS) + ok = false; + } - if (i == XVECLEN (p2, 0)) + if (ok) for (i = 0; i < XVECLEN (p2, 0); i++) if (GET_CODE (XVECEXP (p2, 0, i)) == SET && SET_DEST (XVECEXP (p2, 0, i)) == SET_SRC (PATTERN (i3)))