From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25144 invoked by alias); 24 Jun 2017 03:59:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 1104 invoked by uid 89); 24 Jun 2017 03:59:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=site X-HELO: mail-yw0-f173.google.com Received: from mail-yw0-f173.google.com (HELO mail-yw0-f173.google.com) (209.85.161.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 24 Jun 2017 03:59:12 +0000 Received: by mail-yw0-f173.google.com with SMTP id e142so23105073ywa.1 for ; Fri, 23 Jun 2017 20:59:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=T6uvn9Ss9PEhHbQoxhKFJAe73lrEhm3NqCCG0BfawSY=; b=fZPwZpE6zNe+qFuBTgEWjBw5QRgTDmvnI1FkaDTO5uSiF5xSIm2TNKd3HrmYXO+1D7 FYmP7+eHHp8Qu0lGkzXvBBpuXwemBhnFq3/IUfd5bixTQksh0uUrQhXk3IALWf1weriL BU4jsL8VXpa5VexqdevD3tQoJdBakjfJ6DAqBWpbew7OMuYREs9oHlYj/bLGzXNc+Q1k U5CPkwCZQrEnWF3nEEtCfFUKaXH82dnlKanznVnSfcvyd8NdlYIzQf3Ew6IWM2QFfdo6 w3/s8nM2nOuuwLSnUMch4xByTvqwdr0UpXm2lb9kffkMmXPgzoFUFe5l4crDSwzZdT9G 0gig== X-Gm-Message-State: AKS2vOyK9ede0dSkC+WgbaepvWd7yJedDG4i3qvaRH0XZKgE7c4OzdG/ Grg/M690JOONqUJgYalulvlyeAdrHXBZ X-Received: by 10.129.156.9 with SMTP id t9mr3903782ywg.169.1498276750243; Fri, 23 Jun 2017 20:59:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.47.200 with HTTP; Fri, 23 Jun 2017 20:59:09 -0700 (PDT) From: Andrew Pinski Date: Sat, 24 Jun 2017 03:59:00 -0000 Message-ID: Subject: [PATCH] fold a * (a > 0 ? 1 : -1) to abs(a) and related optimizations To: GCC Patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg01838.txt.bz2 Hi, I saw this on llvm's review site (https://reviews.llvm.org/D34579) and I thought why not add it to GCC. I expanded more than what was done on the LLVM patch. I added the following optimizations: Transform X * (X > 0 ? 1 : -1) into ABS(X). Transform X * (X >= 0 ? 1 : -1) into ABS(X). Transform X * (X > 0.0 ? 1.0 : -1.0) into ABS(X). Transform X * (X >= 0.0 ? 1.0 : -1.0) into ABS(X). Transform X * (X > 0 ? -1 : 1) into -ABS(X). Transform X * (X >= 0 ? -1 : 1) into -ABS(X). Transform X * (X > 0.0 ? -1.0 : 1.0) into -ABS(X). Transform X * (X >= 0.0 ? -1.0 : 1.0) into -ABS(X). Transform X * (X < 0 ? 1 : -1) into -ABS(X). Transform X * (X <= 0 ? 1 : -1) into -ABS(X). Transform X * (X < 0.0 ? 1.0 : -1.0) into -ABS(X). Transform X * (X <= 0.0 ? 1.0 : -1.0) into -ABS(X). Transform X * (X < 0 ? -1 : 1) into ABS(X). Transform X * (X <= 0 ? -1 : 1) into ABS(X). Transform X * (X < 0.0 ? -1.0 : 1.0) into ABS(X). Transform X * (X <= 0.0 ? -1.0 : 1.0) into ABS(X). The floating points ones only happen when not honoring SNANS and not honoring signed zeros. OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions. Thanks, Andrew Pinski ChangeLog: * match.pd ( X * (X >/>=/