From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 51CDC3858C78 for ; Tue, 12 Dec 2023 10:07:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51CDC3858C78 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 51CDC3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::531 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702375657; cv=none; b=fL7J79Nzo3R6ClW8DjDYxfPogDni7zIF1Eh1DqXXJbhZOCpYgHhyBetsXUnENAFb8//aR0Ib4QXMD/wLny4N7tSJZ5qInT28nbij2sBypTqvdadkymiilB1wm8XPYTHTpGbaBTDdYkO3vFmxmiulIHAdqxE+lSUfxYU8B40VJko= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702375657; c=relaxed/simple; bh=0M7o0mzOYmKAJ/aQ5fw1hiO+GbRy7nyJt0fn+ySUcts=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=f4V9PpJTCy9rLwKr7vzuP9AYTdaV4k5BdNPQOZoCz5BAqTorNjQTkOETeGtCUMKA503MWgmx/jX2N4aW3pPnLymV5sdxROaJVrOteK5TSQ/Np4nCT7ZWYG66DMTWq8lIqoBW9pHXH6klpyASSrkKFI5X4qkLgZT+5NcWr7khm3o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-54cb4fa667bso7790416a12.3 for ; Tue, 12 Dec 2023 02:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702375654; x=1702980454; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0M7o0mzOYmKAJ/aQ5fw1hiO+GbRy7nyJt0fn+ySUcts=; b=ateruMdwl6/Pcn0XWNqwCx0cFHOxwJa7ICcNwK6enCL5qBwv/gB10vEnR0Rt6OTNaP 2K2C2cIKRk5I+Pr+mn73n676G7QIx73NbmM0gtz+RmjZ++kTPjcQDF418gYFmA/quckV 0/udUfwvt1VcxNQW4vGfnXaidajtFnaFz0HMAB6aDgHy5TQN+d7xtGaqKTXSp+NfnU/c /QIcg4vrQmQ9a/ip7pqiCu5/AEMV+fw8V+hWVKU0wXyFmJdvIOjU+hIYcwHR6RSMK8hO TAmSPFJMREXatHgdPhNopa9blZUOKM70t3BpTn5Noc2uu/tOiekWj7wHzihOCepG2OWL 9F1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702375654; x=1702980454; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0M7o0mzOYmKAJ/aQ5fw1hiO+GbRy7nyJt0fn+ySUcts=; b=No725RaZn0lE58sy/lGISeUfUs6fNm9N0K6Vdy19Hi9HqaP4ksCykez+dbXP6ib/0a 40lmbFCmEyZU8Td+Z87kuN5M4KVFpmklmy/HmePT/6H30p0piVyPV4c4rGPY/oYzRjbX rdnq0DIJeo1/3I1je5mKi64D5yhJlV6jGe0AFqftRyng0PdCuPZ2z2ORaE3jVD7SU9sh eG0wWswaPZO/2mC7+HGgrVhrDPfS7PSqzjjEX9xZQwPSCqM+qJWJdAfGj7hGVE4I9FE8 9Uw1j0MMUI5yv8c/UJMQp/m1SITYOsArGi5EJYA9whsuBlywLLzTBxxmko4q5G27HUaE AOAw== X-Gm-Message-State: AOJu0Yxhfgi13GpTDiAHetRdZQANGMs2c6l+cwOlJxAAWRzDtO9CjMaw sFfMs9f53BQTV251bCRURdjP2LMIdgQVydlXzYo= X-Google-Smtp-Source: AGHT+IE9mRCaq1w5mFv5s6IyrBKJUGQvMLXo1V7kavahwjPVvyUC6uz93Ed0ujFuQm1XUjvphMSGh8NgvwGQ8HSC9zo= X-Received: by 2002:a17:906:190e:b0:a19:a19b:78d1 with SMTP id a14-20020a170906190e00b00a19a19b78d1mr3071575eje.148.1702375653971; Tue, 12 Dec 2023 02:07:33 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Tue, 12 Dec 2023 09:02:25 +0000 Message-ID: Subject: Re: issue: unexpected results in optimizations To: Jingwen Wu Cc: "gcc@gcc.gnu.org" Content-Type: multipart/alternative; boundary="000000000000211b52060c4d38f4" X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: --000000000000211b52060c4d38f4 Content-Type: text/plain; charset="UTF-8" On Mon, 11 Dec 2023, 17:08 Jingwen Wu via Gcc, wrote: > Hello, I'm sorry to bother you. And I have some gcc compiler optimization > questions to ask you. > First of all, I used csmith tools to generate c files randomly. Meanwhile, > the final running result was the checksum for global variables in a c file. > For the two c files in the attachment, I performed the equivalent > transformation of loop from *initial.**c* to *transformed.c*. And the two > files produced different results (i.e. different checksum values) when > using *-O2* optimization level, while the results of both were the same > when using other levels of optimization such as *-O0*, *-O1*, *-O3*, *-Os*, > *-Ofast*. > Please help me to explain why this is, thank you. > Sometimes csmith can generate invalid code that gets miscompiled. It looks like you're compiling with no warnings, which is a terrible idea: > command line: *gcc file.c -O2 -lm -I $CSMITH_HOME/include && ./a.out* > You should **at least** enable warnings and make sure gcc isn't pointing out any problems in the code. You should also try the options suggested at http://gcc.gnu.org/bugs/ which help identify invalid code. version: gcc 12.2.0 > os: ubuntu 22.04 > --000000000000211b52060c4d38f4--