Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeGen][NFC] Run SROA on complex range tests #131925

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

Maetveis
Copy link
Contributor

@Maetveis Maetveis commented Mar 18, 2025

... to make them shorter and easier to read. This removes ~2000 lines of cruft.

@Maetveis Maetveis added the clang:codegen IR generation bugs: mangling, exceptions, etc. label Mar 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Mészáros Gergely (Maetveis)

Changes

Run mem2reg and sroa passes on the complex range tests, to make them
shorter and easier to read. This removes ~2000 lines of cruft.


Patch is 888.51 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/131925.diff

2 Files Affected:

  • (modified) clang/test/CodeGen/cx-complex-range-real.c (+324-708)
  • (modified) clang/test/CodeGen/cx-complex-range.c (+2375-4159)
diff --git a/clang/test/CodeGen/cx-complex-range-real.c b/clang/test/CodeGen/cx-complex-range-real.c
index 90c37e8669b08..a998869ac39e2 100644
--- a/clang/test/CodeGen/cx-complex-range-real.c
+++ b/clang/test/CodeGen/cx-complex-range-real.c
@@ -1,104 +1,60 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
-// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \
-// RUN: -o - | FileCheck %s --check-prefix=FULL
+// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -triple x86_64-unknown-unknown \
+// RUN: -o - | opt -S -passes=mem2reg,sroa | FileCheck %s --check-prefix=FULL
 
-// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \
-// RUN: -complex-range=improved -o - | FileCheck %s --check-prefix=IMPRVD
+// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -triple x86_64-unknown-unknown \
+// RUN: -complex-range=improved -o - | opt -S -passes=mem2reg,sroa | FileCheck %s --check-prefix=IMPRVD
 
-// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \
-// RUN: -complex-range=promoted -o - | FileCheck %s --check-prefix=PRMTD
+// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -triple x86_64-unknown-unknown \
+// RUN: -complex-range=promoted -o - | opt -S -passes=mem2reg,sroa | FileCheck %s --check-prefix=PRMTD
 
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -complex-range=promoted \
-// RUN: -ffp-contract=off -frounding-math -ffp-exception-behavior=strict \
-// RUN: -emit-llvm -o - %s | FileCheck %s --check-prefix=PRMTD_STRICT
+// RUN: -ffp-contract=off -frounding-math -ffp-exception-behavior=strict -disable-O0-optnone \
+// RUN: -emit-llvm -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s --check-prefix=PRMTD_STRICT
 
 // FULL-LABEL: define dso_local <2 x float> @mulaf(
 // FULL-SAME: <2 x float> noundef [[A_COERCE:%.*]], float noundef [[B:%.*]]) #[[ATTR0:[0-9]+]] {
 // FULL-NEXT:  [[ENTRY:.*:]]
-// FULL-NEXT:    [[RETVAL:%.*]] = alloca { float, float }, align 4
-// FULL-NEXT:    [[A:%.*]] = alloca { float, float }, align 4
-// FULL-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// FULL-NEXT:    store <2 x float> [[A_COERCE]], ptr [[A]], align 4
-// FULL-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// FULL-NEXT:    [[A_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
-// FULL-NEXT:    [[A_REAL:%.*]] = load float, ptr [[A_REALP]], align 4
-// FULL-NEXT:    [[A_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
-// FULL-NEXT:    [[A_IMAG:%.*]] = load float, ptr [[A_IMAGP]], align 4
-// FULL-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// FULL-NEXT:    [[MUL_RL:%.*]] = fmul float [[A_REAL]], [[TMP0]]
-// FULL-NEXT:    [[MUL_IL:%.*]] = fmul float [[A_IMAG]], [[TMP0]]
-// FULL-NEXT:    [[RETVAL_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 0
-// FULL-NEXT:    [[RETVAL_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 1
-// FULL-NEXT:    store float [[MUL_RL]], ptr [[RETVAL_REALP]], align 4
-// FULL-NEXT:    store float [[MUL_IL]], ptr [[RETVAL_IMAGP]], align 4
-// FULL-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[RETVAL]], align 4
-// FULL-NEXT:    ret <2 x float> [[TMP1]]
+// FULL-NEXT:    [[A_SROA_0_0_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 0
+// FULL-NEXT:    [[A_SROA_0_4_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 1
+// FULL-NEXT:    [[MUL_RL:%.*]] = fmul float [[A_SROA_0_0_VEC_EXTRACT]], [[B]]
+// FULL-NEXT:    [[MUL_IL:%.*]] = fmul float [[A_SROA_0_4_VEC_EXTRACT]], [[B]]
+// FULL-NEXT:    [[RETVAL_SROA_0_0_VEC_INSERT:%.*]] = insertelement <2 x float> undef, float [[MUL_RL]], i32 0
+// FULL-NEXT:    [[RETVAL_SROA_0_4_VEC_INSERT:%.*]] = insertelement <2 x float> [[RETVAL_SROA_0_0_VEC_INSERT]], float [[MUL_IL]], i32 1
+// FULL-NEXT:    ret <2 x float> [[RETVAL_SROA_0_4_VEC_INSERT]]
 //
 // IMPRVD-LABEL: define dso_local <2 x float> @mulaf(
 // IMPRVD-SAME: <2 x float> noundef [[A_COERCE:%.*]], float noundef [[B:%.*]]) #[[ATTR0:[0-9]+]] {
 // IMPRVD-NEXT:  [[ENTRY:.*:]]
-// IMPRVD-NEXT:    [[RETVAL:%.*]] = alloca { float, float }, align 4
-// IMPRVD-NEXT:    [[A:%.*]] = alloca { float, float }, align 4
-// IMPRVD-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// IMPRVD-NEXT:    store <2 x float> [[A_COERCE]], ptr [[A]], align 4
-// IMPRVD-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// IMPRVD-NEXT:    [[A_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
-// IMPRVD-NEXT:    [[A_REAL:%.*]] = load float, ptr [[A_REALP]], align 4
-// IMPRVD-NEXT:    [[A_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
-// IMPRVD-NEXT:    [[A_IMAG:%.*]] = load float, ptr [[A_IMAGP]], align 4
-// IMPRVD-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// IMPRVD-NEXT:    [[MUL_RL:%.*]] = fmul float [[A_REAL]], [[TMP0]]
-// IMPRVD-NEXT:    [[MUL_IL:%.*]] = fmul float [[A_IMAG]], [[TMP0]]
-// IMPRVD-NEXT:    [[RETVAL_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 0
-// IMPRVD-NEXT:    [[RETVAL_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 1
-// IMPRVD-NEXT:    store float [[MUL_RL]], ptr [[RETVAL_REALP]], align 4
-// IMPRVD-NEXT:    store float [[MUL_IL]], ptr [[RETVAL_IMAGP]], align 4
-// IMPRVD-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[RETVAL]], align 4
-// IMPRVD-NEXT:    ret <2 x float> [[TMP1]]
+// IMPRVD-NEXT:    [[A_SROA_0_0_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 0
+// IMPRVD-NEXT:    [[A_SROA_0_4_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 1
+// IMPRVD-NEXT:    [[MUL_RL:%.*]] = fmul float [[A_SROA_0_0_VEC_EXTRACT]], [[B]]
+// IMPRVD-NEXT:    [[MUL_IL:%.*]] = fmul float [[A_SROA_0_4_VEC_EXTRACT]], [[B]]
+// IMPRVD-NEXT:    [[RETVAL_SROA_0_0_VEC_INSERT:%.*]] = insertelement <2 x float> undef, float [[MUL_RL]], i32 0
+// IMPRVD-NEXT:    [[RETVAL_SROA_0_4_VEC_INSERT:%.*]] = insertelement <2 x float> [[RETVAL_SROA_0_0_VEC_INSERT]], float [[MUL_IL]], i32 1
+// IMPRVD-NEXT:    ret <2 x float> [[RETVAL_SROA_0_4_VEC_INSERT]]
 //
 // PRMTD-LABEL: define dso_local <2 x float> @mulaf(
 // PRMTD-SAME: <2 x float> noundef [[A_COERCE:%.*]], float noundef [[B:%.*]]) #[[ATTR0:[0-9]+]] {
 // PRMTD-NEXT:  [[ENTRY:.*:]]
-// PRMTD-NEXT:    [[RETVAL:%.*]] = alloca { float, float }, align 4
-// PRMTD-NEXT:    [[A:%.*]] = alloca { float, float }, align 4
-// PRMTD-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// PRMTD-NEXT:    store <2 x float> [[A_COERCE]], ptr [[A]], align 4
-// PRMTD-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// PRMTD-NEXT:    [[A_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
-// PRMTD-NEXT:    [[A_REAL:%.*]] = load float, ptr [[A_REALP]], align 4
-// PRMTD-NEXT:    [[A_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
-// PRMTD-NEXT:    [[A_IMAG:%.*]] = load float, ptr [[A_IMAGP]], align 4
-// PRMTD-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// PRMTD-NEXT:    [[MUL_RL:%.*]] = fmul float [[A_REAL]], [[TMP0]]
-// PRMTD-NEXT:    [[MUL_IL:%.*]] = fmul float [[A_IMAG]], [[TMP0]]
-// PRMTD-NEXT:    [[RETVAL_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 0
-// PRMTD-NEXT:    [[RETVAL_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 1
-// PRMTD-NEXT:    store float [[MUL_RL]], ptr [[RETVAL_REALP]], align 4
-// PRMTD-NEXT:    store float [[MUL_IL]], ptr [[RETVAL_IMAGP]], align 4
-// PRMTD-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[RETVAL]], align 4
-// PRMTD-NEXT:    ret <2 x float> [[TMP1]]
+// PRMTD-NEXT:    [[A_SROA_0_0_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 0
+// PRMTD-NEXT:    [[A_SROA_0_4_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 1
+// PRMTD-NEXT:    [[MUL_RL:%.*]] = fmul float [[A_SROA_0_0_VEC_EXTRACT]], [[B]]
+// PRMTD-NEXT:    [[MUL_IL:%.*]] = fmul float [[A_SROA_0_4_VEC_EXTRACT]], [[B]]
+// PRMTD-NEXT:    [[RETVAL_SROA_0_0_VEC_INSERT:%.*]] = insertelement <2 x float> undef, float [[MUL_RL]], i32 0
+// PRMTD-NEXT:    [[RETVAL_SROA_0_4_VEC_INSERT:%.*]] = insertelement <2 x float> [[RETVAL_SROA_0_0_VEC_INSERT]], float [[MUL_IL]], i32 1
+// PRMTD-NEXT:    ret <2 x float> [[RETVAL_SROA_0_4_VEC_INSERT]]
 //
 // PRMTD_STRICT-LABEL: define dso_local <2 x float> @mulaf(
 // PRMTD_STRICT-SAME: <2 x float> noundef [[A_COERCE:%.*]], float noundef [[B:%.*]]) #[[ATTR0:[0-9]+]] {
 // PRMTD_STRICT-NEXT:  [[ENTRY:.*:]]
-// PRMTD_STRICT-NEXT:    [[RETVAL:%.*]] = alloca { float, float }, align 4
-// PRMTD_STRICT-NEXT:    [[A:%.*]] = alloca { float, float }, align 4
-// PRMTD_STRICT-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// PRMTD_STRICT-NEXT:    store <2 x float> [[A_COERCE]], ptr [[A]], align 4
-// PRMTD_STRICT-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// PRMTD_STRICT-NEXT:    [[A_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
-// PRMTD_STRICT-NEXT:    [[A_REAL:%.*]] = load float, ptr [[A_REALP]], align 4
-// PRMTD_STRICT-NEXT:    [[A_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
-// PRMTD_STRICT-NEXT:    [[A_IMAG:%.*]] = load float, ptr [[A_IMAGP]], align 4
-// PRMTD_STRICT-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// PRMTD_STRICT-NEXT:    [[MUL_RL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[A_REAL]], float [[TMP0]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3:[0-9]+]]
-// PRMTD_STRICT-NEXT:    [[MUL_IL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[A_IMAG]], float [[TMP0]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]]
-// PRMTD_STRICT-NEXT:    [[RETVAL_REALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 0
-// PRMTD_STRICT-NEXT:    [[RETVAL_IMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RETVAL]], i32 0, i32 1
-// PRMTD_STRICT-NEXT:    store float [[MUL_RL]], ptr [[RETVAL_REALP]], align 4
-// PRMTD_STRICT-NEXT:    store float [[MUL_IL]], ptr [[RETVAL_IMAGP]], align 4
-// PRMTD_STRICT-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[RETVAL]], align 4
-// PRMTD_STRICT-NEXT:    ret <2 x float> [[TMP1]]
+// PRMTD_STRICT-NEXT:    [[A_SROA_0_0_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 0
+// PRMTD_STRICT-NEXT:    [[A_SROA_0_4_VEC_EXTRACT:%.*]] = extractelement <2 x float> [[A_COERCE]], i32 1
+// PRMTD_STRICT-NEXT:    [[MUL_RL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[A_SROA_0_0_VEC_EXTRACT]], float [[B]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3:[0-9]+]]
+// PRMTD_STRICT-NEXT:    [[MUL_IL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[A_SROA_0_4_VEC_EXTRACT]], float [[B]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]]
+// PRMTD_STRICT-NEXT:    [[RETVAL_SROA_0_0_VEC_INSERT:%.*]] = insertelement <2 x float> undef, float [[MUL_RL]], i32 0
+// PRMTD_STRICT-NEXT:    [[RETVAL_SROA_0_4_VEC_INSERT:%.*]] = insertelement <2 x float> [[RETVAL_SROA_0_0_VEC_INSERT]], float [[MUL_IL]], i32 1
+// PRMTD_STRICT-NEXT:    ret <2 x float> [[RETVAL_SROA_0_4_VEC_INSERT]]
 //
 _Complex float mulaf(_Complex float a, float b) {
   return a * b;
@@ -107,20 +63,14 @@ _Complex float mulaf(_Complex float a, float b) {
 // FULL-LABEL: define dso_local void @mulassignf(
 // FULL-SAME: ptr noundef [[A:%.*]], float noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
 // FULL-NEXT:  [[ENTRY:.*:]]
-// FULL-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
-// FULL-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// FULL-NEXT:    store ptr [[A]], ptr [[A_ADDR]], align 8
-// FULL-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// FULL-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// FULL-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8
-// FULL-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
+// FULL-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
 // FULL-NEXT:    [[DOTREAL:%.*]] = load float, ptr [[DOTREALP]], align 4
-// FULL-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// FULL-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // FULL-NEXT:    [[DOTIMAG:%.*]] = load float, ptr [[DOTIMAGP]], align 4
-// FULL-NEXT:    [[MUL_RL:%.*]] = fmul float [[DOTREAL]], [[TMP0]]
-// FULL-NEXT:    [[MUL_IL:%.*]] = fmul float [[DOTIMAG]], [[TMP0]]
-// FULL-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
-// FULL-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// FULL-NEXT:    [[MUL_RL:%.*]] = fmul float [[DOTREAL]], [[B]]
+// FULL-NEXT:    [[MUL_IL:%.*]] = fmul float [[DOTIMAG]], [[B]]
+// FULL-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
+// FULL-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // FULL-NEXT:    store float [[MUL_RL]], ptr [[DOTREALP1]], align 4
 // FULL-NEXT:    store float [[MUL_IL]], ptr [[DOTIMAGP2]], align 4
 // FULL-NEXT:    ret void
@@ -128,20 +78,14 @@ _Complex float mulaf(_Complex float a, float b) {
 // IMPRVD-LABEL: define dso_local void @mulassignf(
 // IMPRVD-SAME: ptr noundef [[A:%.*]], float noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
 // IMPRVD-NEXT:  [[ENTRY:.*:]]
-// IMPRVD-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
-// IMPRVD-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// IMPRVD-NEXT:    store ptr [[A]], ptr [[A_ADDR]], align 8
-// IMPRVD-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// IMPRVD-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// IMPRVD-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8
-// IMPRVD-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
+// IMPRVD-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
 // IMPRVD-NEXT:    [[DOTREAL:%.*]] = load float, ptr [[DOTREALP]], align 4
-// IMPRVD-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// IMPRVD-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // IMPRVD-NEXT:    [[DOTIMAG:%.*]] = load float, ptr [[DOTIMAGP]], align 4
-// IMPRVD-NEXT:    [[MUL_RL:%.*]] = fmul float [[DOTREAL]], [[TMP0]]
-// IMPRVD-NEXT:    [[MUL_IL:%.*]] = fmul float [[DOTIMAG]], [[TMP0]]
-// IMPRVD-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
-// IMPRVD-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// IMPRVD-NEXT:    [[MUL_RL:%.*]] = fmul float [[DOTREAL]], [[B]]
+// IMPRVD-NEXT:    [[MUL_IL:%.*]] = fmul float [[DOTIMAG]], [[B]]
+// IMPRVD-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
+// IMPRVD-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // IMPRVD-NEXT:    store float [[MUL_RL]], ptr [[DOTREALP1]], align 4
 // IMPRVD-NEXT:    store float [[MUL_IL]], ptr [[DOTIMAGP2]], align 4
 // IMPRVD-NEXT:    ret void
@@ -149,20 +93,14 @@ _Complex float mulaf(_Complex float a, float b) {
 // PRMTD-LABEL: define dso_local void @mulassignf(
 // PRMTD-SAME: ptr noundef [[A:%.*]], float noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
 // PRMTD-NEXT:  [[ENTRY:.*:]]
-// PRMTD-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
-// PRMTD-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// PRMTD-NEXT:    store ptr [[A]], ptr [[A_ADDR]], align 8
-// PRMTD-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// PRMTD-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// PRMTD-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8
-// PRMTD-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
+// PRMTD-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
 // PRMTD-NEXT:    [[DOTREAL:%.*]] = load float, ptr [[DOTREALP]], align 4
-// PRMTD-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// PRMTD-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // PRMTD-NEXT:    [[DOTIMAG:%.*]] = load float, ptr [[DOTIMAGP]], align 4
-// PRMTD-NEXT:    [[MUL_RL:%.*]] = fmul float [[DOTREAL]], [[TMP0]]
-// PRMTD-NEXT:    [[MUL_IL:%.*]] = fmul float [[DOTIMAG]], [[TMP0]]
-// PRMTD-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
-// PRMTD-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// PRMTD-NEXT:    [[MUL_RL:%.*]] = fmul float [[DOTREAL]], [[B]]
+// PRMTD-NEXT:    [[MUL_IL:%.*]] = fmul float [[DOTIMAG]], [[B]]
+// PRMTD-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
+// PRMTD-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // PRMTD-NEXT:    store float [[MUL_RL]], ptr [[DOTREALP1]], align 4
 // PRMTD-NEXT:    store float [[MUL_IL]], ptr [[DOTIMAGP2]], align 4
 // PRMTD-NEXT:    ret void
@@ -170,20 +108,14 @@ _Complex float mulaf(_Complex float a, float b) {
 // PRMTD_STRICT-LABEL: define dso_local void @mulassignf(
 // PRMTD_STRICT-SAME: ptr noundef [[A:%.*]], float noundef [[B:%.*]]) #[[ATTR2:[0-9]+]] {
 // PRMTD_STRICT-NEXT:  [[ENTRY:.*:]]
-// PRMTD_STRICT-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
-// PRMTD_STRICT-NEXT:    [[B_ADDR:%.*]] = alloca float, align 4
-// PRMTD_STRICT-NEXT:    store ptr [[A]], ptr [[A_ADDR]], align 8
-// PRMTD_STRICT-NEXT:    store float [[B]], ptr [[B_ADDR]], align 4
-// PRMTD_STRICT-NEXT:    [[TMP0:%.*]] = load float, ptr [[B_ADDR]], align 4
-// PRMTD_STRICT-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8
-// PRMTD_STRICT-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
+// PRMTD_STRICT-NEXT:    [[DOTREALP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
 // PRMTD_STRICT-NEXT:    [[DOTREAL:%.*]] = load float, ptr [[DOTREALP]], align 4
-// PRMTD_STRICT-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// PRMTD_STRICT-NEXT:    [[DOTIMAGP:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // PRMTD_STRICT-NEXT:    [[DOTIMAG:%.*]] = load float, ptr [[DOTIMAGP]], align 4
-// PRMTD_STRICT-NEXT:    [[MUL_RL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[DOTREAL]], float [[TMP0]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]]
-// PRMTD_STRICT-NEXT:    [[MUL_IL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[DOTIMAG]], float [[TMP0]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]]
-// PRMTD_STRICT-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 0
-// PRMTD_STRICT-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[TMP1]], i32 0, i32 1
+// PRMTD_STRICT-NEXT:    [[MUL_RL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[DOTREAL]], float [[B]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]]
+// PRMTD_STRICT-NEXT:    [[MUL_IL:%.*]] = call float @llvm.experimental.constrained.fmul.f32(float [[DOTIMAG]], float [[B]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]]
+// PRMTD_STRICT-NEXT:    [[DOTREALP1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 0
+// PRMTD_STRICT-NEXT:    [[DOTIMAGP2:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[A]], i32 0, i32 1
 // PRMTD_STRICT-NEXT:    store float [[MUL_RL]], ptr [[DOTREALP1]], align 4
 // PRMTD_STRICT-NEXT:    store float [[MUL_IL]], ptr [[DOTIMAGP2]], align 4
 // PRMTD_STRICT-NEXT:    ret void
@@ -195...
[truncated]

@Maetveis Maetveis requested a review from efriedma-quic March 18, 2025 22:01
@Maetveis Maetveis marked this pull request as ready for review March 18, 2025 22:01
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 18, 2025
Copy link

github-actions bot commented Mar 18, 2025

⚠️ undef deprecator found issues in your code. ⚠️

You can test this locally with the following command:
git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' f017073cd8ac9e627db17678c6b64e9abe4fbec7 6dbcb05340584187761da8dd46193dab0db0ae5d clang/test/CodeGen/cx-complex-range-real.c clang/test/CodeGen/cx-complex-range.c

The following files introduce new uses of undef:

  • clang/test/CodeGen/cx-complex-range-real.c
  • clang/test/CodeGen/cx-complex-range.c

Undef is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields undef. You should use poison values for placeholders instead.

In tests, avoid using undef and having tests that trigger undefined behavior. If you need an operand with some unimportant value, you can add a new argument to the function and use that instead.

For example, this is considered a bad practice:

define void @fn() {
  ...
  br i1 undef, ...
}

Please use the following instead:

define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}

Please refer to the Undefined Behavior Manual for more information.

@Maetveis
Copy link
Contributor Author

Maetveis commented Mar 18, 2025

⚠️ undef deprecator found issues in your code. ⚠️
You can test this locally with the following command:

The following files introduce new uses of undef:

* clang/test/CodeGen/cx-complex-range-real.c

* clang/test/CodeGen/cx-complex-range.c

Hmm these were added by sroa I believe, for the "buildvector" idiom, curious that some instances got poison, but not all.

EDIT: insertelement seems to be undef, while insertvalue is poison.

@Maetveis Maetveis force-pushed the users/Maetveis/simplify_complex_tests_with_opt branch from ce2752e to 6da24fc Compare March 19, 2025 06:19
@Maetveis Maetveis force-pushed the users/Maetveis/complex-promoted-fix-assign branch from f02c8a6 to 57b488a Compare March 19, 2025 06:19
@Maetveis Maetveis marked this pull request as draft March 19, 2025 06:21
@Maetveis Maetveis force-pushed the users/Maetveis/complex-promoted-fix-assign branch from 57b488a to f2a2bf5 Compare March 19, 2025 06:27
Base automatically changed from users/Maetveis/complex-promoted-fix-assign to main March 19, 2025 06:29
Run mem2reg and sroa passes on the complex range tests, to make them
shorter and easier to read. This removes ~2000 lines of cruft.
@Maetveis Maetveis force-pushed the users/Maetveis/simplify_complex_tests_with_opt branch from 6da24fc to 1ecc06b Compare March 19, 2025 06:31
@efriedma-quic
Copy link
Collaborator

Running both mem2reg and sroa is redunant; just run sroa.

If the undefs are getting introduced by sroa, that's fine; they'll go away when we fix sroa.

@Maetveis Maetveis changed the title [CodeGen][NFC] Run mem2reg and sroa on complex range tests [CodeGen][NFC] Run SROA on complex range tests Mar 25, 2025
@Maetveis Maetveis marked this pull request as ready for review March 25, 2025 19:39
@Maetveis
Copy link
Contributor Author

Maetveis commented Mar 25, 2025

Running both mem2reg and sroa is redunant; just run sroa.

If the undefs are getting introduced by sroa, that's fine; they'll go away when we fix sroa.

Okay, thanks. I've updated the PR to remove the explicit mem2reg.

Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Maetveis Maetveis merged commit a8588d8 into main Mar 26, 2025
12 of 13 checks passed
@Maetveis Maetveis deleted the users/Maetveis/simplify_complex_tests_with_opt branch March 26, 2025 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants