From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 493BF3858005 for ; Tue, 17 Oct 2023 09:20:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 493BF3858005 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 493BF3858005 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697534441; cv=none; b=xwU6becCbPr7UnQLMPsMlkOk+R1dnZ7a6OGs2S+9N/1/yGqJCmqM2EdQEz1VBIV/0uUG2EcXPdRq6AuO5K1ye68vBarNJx6tYaLNN6Z+9SijWCr2NYmww5A+gf+Pw/gdrPeavTDSagbfaIXzunGB23w99HXun9TTFfVvcUTYnvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697534441; c=relaxed/simple; bh=mDbBEvy8Yxnc/lpwNuA2RpyLLlZHw/hZPnPKOCW+2f4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=lP7MCALpj0Lgz67/DAAHouh38EhZxxAqscZ1qtgy900esDzqYmVqmskpc6n9VoPqHoJO8QV+UaiYWeqeekKXK0OAebGwNDo8+7Jke8D2PJoREmyakVEMz+8GxD+hjRlF41OCA459JFS3kti6IMlZ1JiLjDdQ2qz9Bq3Zg9aVNys= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b9338e4695so70938211fa.2 for ; Tue, 17 Oct 2023 02:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697534438; x=1698139238; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=mDbBEvy8Yxnc/lpwNuA2RpyLLlZHw/hZPnPKOCW+2f4=; b=i530BkLy2jftpong4xdftd+xXSf06hUSh30LIAg4DCtXwvXXAxKaXF76352ZtaOwqp cqi7E7pmzhuN/zndxusl/Zqjc51r4DjD//nPLZE4JjUUwoxpeVtsjIoKLJTG7ZOSAFso tgiCyaCgDdpDe2AcKgXXJ5Kv5wspAzjTlYgEeSZFGIGMQYvU3IHnZUMD6m/9g4Y+mSDE zJz1PcMl6okN2A9eZdmA2N8Gd7qz01XM9NnpL21tn/X8h7b2y5+gLA4nvqc/3B0YuKUc 1KAVIhX6JSOq8rh7Uw65mwwE9rKf3r/Db9+Nz2jplXne2zNOWGku019S9uTWLIzrhZo6 rjPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697534438; x=1698139238; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mDbBEvy8Yxnc/lpwNuA2RpyLLlZHw/hZPnPKOCW+2f4=; b=pCvarnldVRtFeEnRePw2AUI4rTE0h+oe4PhzZhlYubrJxV1xVDvIvIQG0yn0YDgLZX 7mQpL5L8uLLNSCdMlkxo1Sh8nxgSytF+ZCKBRv2UTemACTXZrnWO5k3RqreW21AJUkku BjzpuFIxu8OHdpZdhVnrvHXxQ2QeugimBGI6cbM4Yv97uZ/4DSfuwQTE8Uq2f2MjTFRu hkKeMX+6lSqzHhsQ0UIZF1K955etShf3yf1Np8wBsBStYqg/6X201bkAd9gBR70f2zjQ gkwKNDO+6+vS53jL240IRqy4R9epCpyu4ptST9f62rm2CtXoL+QoU1NPJTn+ErY6w+/y AdDw== X-Gm-Message-State: AOJu0Yw3P4CPM/MvvvS6iwe+YNXewJKLF18HxBAhGhv3u5TdM2oqPB7q 7EUAVdEpWrsFDGxjuk90LNIV59Q+TVFyR5ANcrfjjZgJHeLUjw== X-Google-Smtp-Source: AGHT+IHkT49LP1dFZAVx+jaDZxTuvcP7UPKQYj003DDIR/K3CcrgSEJF/O0uEwQ4gLRCpqmp/ikkAhXGsPxOglf+hkw= X-Received: by 2002:a05:651c:4c6:b0:2c5:1d11:5691 with SMTP id e6-20020a05651c04c600b002c51d115691mr1811944lji.28.1697534438083; Tue, 17 Oct 2023 02:20:38 -0700 (PDT) MIME-Version: 1.0 From: Hanke Zhang Date: Tue, 17 Oct 2023 17:20:26 +0800 Message-ID: Subject: Check whether a function is a pure function To: gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,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: Hi, I'm trying to write a pass to erase some useless functions or to put it another way, detect whether a function is pure or not. (Of course I know some passes can do the clean after inline) Here is the problem I got, If a function satisfy the following points, can it be considered safe to delete? 1. return value is ignored or has no return 2. params are pure 32bit Integer Const or has no params 3. No use of global variable 4. No function call, assembly code, goto statement 5. No cast And in my pass, I try to do these things through these points: 1. check GIMPLE_RETURN statement and check all the function call points 2. check DECL_PARAM(fndecl) and check the input params at all the function call points 3. check that fndecl is not in the global_var->referring list 4. check GIMPLE_CALL, GIMPLE_ASM, GIMPLE_GOTO are not present 5. check that there is no difference between TREE_TYPE(lhs) and TREE_TYPE(rhs1) types in the GIMPLE_ASSIGN statement I would like to ask that if there are any omissions or errors in the prerequisites and corresponding implementation plans I listed above. Thanks Hanke Zhang