From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 72FA7385626B for ; Mon, 27 Jun 2022 02:47:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72FA7385626B Received: by mail-ej1-x634.google.com with SMTP id d2so4418391ejy.1 for ; Sun, 26 Jun 2022 19:47:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=2T0q1JNq9EMMs2Kix0tum8cWq+IHRM5G2Jk71rvvR64=; b=aHgbUYhmOIh/bsNcJt/YGpdUYDOTQahdla6xdeBCAdpTGuVs/nDVJLViFgr3s5IKmX VNH0KNq6CZ5zVNgJSkiMBILJVdKVbQKhgV6sLf2EyEAC+9C95FSOJ7gJGiGXDWp5dMOi hSIz3zCRqIdh9oSZvRgDmvMM4/r8ajbOisOVRixjjDF+NH+Y3wHzcKKrVaDvzkS4if7U Y/IwXsJVZonMYARVvlmLYNlmqOihhrirU6a/8SttnHjbHfKMtEvXXdNhhrX9TaUQhpB8 /F+0NeLLpniXXl6WEkMN1dDXbS/idA3TAXGwCl7465nrzOjblQOWUbTeQzu+QvfuELVt NQ4Q== X-Gm-Message-State: AJIora/3Dhs6Jf4DhTy/thXKKD3P2xQ3Vxn7IdFhG9WlzwtwJ/WQi5JV Vq9y09ExQDdlbdt0mjH+JE5RiXveEzvLixncD6kFXpIrtt8= X-Google-Smtp-Source: AGRyM1tlAvZEKifBnOy4uYyNGSf2q4PX7bi/E00tz2E9s7uoBgJoe70/Bpy3LlJ82WcfHUI68xdPwibpG4E+CEvOSdw= X-Received: by 2002:a17:907:3f8d:b0:726:2ab9:f2fc with SMTP id hr13-20020a1709073f8d00b007262ab9f2fcmr10743379ejc.313.1656298054874; Sun, 26 Jun 2022 19:47:34 -0700 (PDT) MIME-Version: 1.0 From: Adonis Ling Date: Mon, 27 Jun 2022 10:47:24 +0800 Message-ID: Subject: Why does different types of array subscript used to iterate affect auto vectorization To: gcc-help@gcc.gnu.org X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, HTML_MESSAGE, 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 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jun 2022 02:47:38 -0000 Hi all, Recently, I met an issue with auto vectorization. As following code shows, why uint32_t prevents the compiler (GCC 12.1 + O3) from optimizing by auto vectorization. See https://godbolt.org/z/a3GfaKEq6. #include // no auto vectorization void test32(uint32_t *array, uint32_t &nread, uint32_t from, uint32_t to) { for (uint32_t i = from; i < to; i++) { array[nread++] = i; } } // auto vectorization void test64(uint32_t *array, uint64_t &nread, uint32_t from, uint32_t to) { for (uint32_t i = from; i < to; i++) { array[nread++] = i; } } // no auto vectorization void test_another_32(uint32_t *array, uint32_t &nread, uint32_t from, uint32_t to) { uint32_t index = nread; for (uint32_t i = from; i < to; i++) { array[index++] = i; } nread = index; } // auto vectorization void test_another_64(uint32_t *array, uint32_t &nread, uint32_t from, uint32_t to) { uint64_t index = nread; for (uint32_t i = from; i < to; i++) { array[index++] = i; } nread = index; } After I ran the command g++ -O3 -fopt-info-vec-missed -c test.cc -o /dev/null, I got the following result. How to interpret it? bash> g++ -O3 -fopt-info-vec-missed -c test.cc -o /dev/null test.cc:5:31: missed: couldn't vectorize loop test.cc:6:24: missed: not vectorized: not suitable for scatter store *_5 = i_18; test.cc:21:31: missed: couldn't vectorize loop test.cc:22:24: missed: not vectorized: not suitable for scatter store *_4 = i_22; -- Best regards, Adonis