diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -11073,7 +11073,7 @@ break; case Linear: Out << 'l'; - if (!!ParamAttr.StrideOrArg) + if (ParamAttr.StrideOrArg != 1) Out << ParamAttr.StrideOrArg; break; case Uniform: @@ -11213,7 +11213,7 @@ Out << 'l'; // Don't print the step value if it is not present or if it is // equal to 1. - if (!!ParamAttr.StrideOrArg && ParamAttr.StrideOrArg != 1) + if (ParamAttr.StrideOrArg != 1) Out << ParamAttr.StrideOrArg; break; case Uniform: @@ -11451,15 +11451,24 @@ for (const Expr *E : Attr->linears()) { E = E->IgnoreParenImpCasts(); unsigned Pos; + // Rescaling factor needed to compute the linear parameter + // value in the mangled name. + unsigned PtrRescalingFactor = 1; if (isa(E)) { Pos = ParamPositions[FD]; } else { const auto *PVD = cast(cast(E)->getDecl()) ->getCanonicalDecl(); Pos = ParamPositions[PVD]; + if (auto *P = dyn_cast(PVD->getType())) + PtrRescalingFactor = CGM.getContext() + .getTypeSizeInChars(P->getPointeeType()) + .getQuantity(); } ParamAttrTy &ParamAttr = ParamAttrs[Pos]; ParamAttr.Kind = Linear; + // Assuming a stride of 1, for `linear` without modifiers. + ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(1); if (*SI) { Expr::EvalResult Result; if (!(*SI)->EvaluateAsInt(Result, C, Expr::SE_AllowSideEffects)) { @@ -11475,6 +11484,11 @@ ParamAttr.StrideOrArg = Result.Val.getInt(); } } + // If we are using a linear clause on a pointer, we need to + // rescale the value of linear_step with the byte size of the + // pointee type. + if (Linear == ParamAttr.Kind) + ParamAttr.StrideOrArg = ParamAttr.StrideOrArg * PtrRescalingFactor; ++SI; ++MI; } diff --git a/clang/test/OpenMP/declare_simd_aarch64.c b/clang/test/OpenMP/declare_simd_aarch64.c --- a/clang/test/OpenMP/declare_simd_aarch64.c +++ b/clang/test/OpenMP/declare_simd_aarch64.c @@ -130,12 +130,12 @@ /*************************/ #pragma omp declare simd linear(sin) linear(cos) void sincos(double in, double *sin, double *cos); -// AARCH64: "_ZGVnN2vll_sincos" +// AARCH64: "_ZGVnN2vl8l8_sincos" // AARCH64-NOT: sincos #pragma omp declare simd linear(sin : 1) linear(cos : 2) void SinCos(double in, double *sin, double *cos); -// AARCH64: "_ZGVnN2vll2_SinCos" +// AARCH64: "_ZGVnN2vl8l16_SinCos" // AARCH64-NOT: SinCos // Selection of tests based on the examples provided in chapter 5 of @@ -158,7 +158,7 @@ // Listing 6, p. 19 #pragma omp declare simd linear(x) aligned(x : 16) simdlen(4) int foo4(int *x, float y); -// AARCH64: "_ZGVnM4la16v_foo4" "_ZGVnN4la16v_foo4" +// AARCH64: "_ZGVnM4l4a16v_foo4" "_ZGVnN4l4a16v_foo4" // AARCH64-NOT: foo4 static int *I; diff --git a/clang/test/OpenMP/declare_simd_codegen.cpp b/clang/test/OpenMP/declare_simd_codegen.cpp --- a/clang/test/OpenMP/declare_simd_codegen.cpp +++ b/clang/test/OpenMP/declare_simd_codegen.cpp @@ -136,14 +136,14 @@ // CHECK-DAG: declare {{.+}}@_Z5add_2Pf( // CHECK-DAG: define {{.+}}@_Z11constlineari( -// CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf" -// CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf" -// CHECK-DAG: "_ZGVcM8l8__Z5add_1Pf" -// CHECK-DAG: "_ZGVcN8l8__Z5add_1Pf" -// CHECK-DAG: "_ZGVdM8l8__Z5add_1Pf" -// CHECK-DAG: "_ZGVdN8l8__Z5add_1Pf" -// CHECK-DAG: "_ZGVeM16l8__Z5add_1Pf" -// CHECK-DAG: "_ZGVeN16l8__Z5add_1Pf" +// CHECK-DAG: "_ZGVbM4l32__Z5add_1Pf" +// CHECK-DAG: "_ZGVbN4l32__Z5add_1Pf" +// CHECK-DAG: "_ZGVcM8l32__Z5add_1Pf" +// CHECK-DAG: "_ZGVcN8l32__Z5add_1Pf" +// CHECK-DAG: "_ZGVdM8l32__Z5add_1Pf" +// CHECK-DAG: "_ZGVdN8l32__Z5add_1Pf" +// CHECK-DAG: "_ZGVeM16l32__Z5add_1Pf" +// CHECK-DAG: "_ZGVeN16l32__Z5add_1Pf" // CHECK-DAG: "_ZGVbM32v__Z5add_1Pf" // CHECK-DAG: "_ZGVcM32v__Z5add_1Pf" // CHECK-DAG: "_ZGVdM32v__Z5add_1Pf" @@ -180,14 +180,14 @@ // CHECK-DAG: "_ZGVeM16uus1__ZN2VV3addEii" // CHECK-DAG: "_ZGVeN16uus1__ZN2VV3addEii" -// CHECK-DAG: "_ZGVbM4lla16l4a4__ZN2VV6taddpfEPfRS0_" -// CHECK-DAG: "_ZGVbN4lla16l4a4__ZN2VV6taddpfEPfRS0_" -// CHECK-DAG: "_ZGVcM8lla16l4a4__ZN2VV6taddpfEPfRS0_" -// CHECK-DAG: "_ZGVcN8lla16l4a4__ZN2VV6taddpfEPfRS0_" -// CHECK-DAG: "_ZGVdM8lla16l4a4__ZN2VV6taddpfEPfRS0_" -// CHECK-DAG: "_ZGVdN8lla16l4a4__ZN2VV6taddpfEPfRS0_" -// CHECK-DAG: "_ZGVeM16lla16l4a4__ZN2VV6taddpfEPfRS0_" -// CHECK-DAG: "_ZGVeN16lla16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVbM4ll4a16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVbN4ll4a16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVcM8ll4a16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVcN8ll4a16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVdM8ll4a16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVdN8ll4a16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVeM16ll4a16l4a4__ZN2VV6taddpfEPfRS0_" +// CHECK-DAG: "_ZGVeN16ll4a16l4a4__ZN2VV6taddpfEPfRS0_" // CHECK-DAG: "_ZGVbM4vvl8__ZN2VV4taddERA_iRi" // CHECK-DAG: "_ZGVbN4vvl8__ZN2VV4taddERA_iRi" @@ -293,23 +293,23 @@ // CHECK-DAG: "_ZGVeM16vvv__Z3bax2VVPdi" // CHECK-DAG: "_ZGVeN16vvv__Z3bax2VVPdi" -// CHECK-DAG: "_ZGVbM4ua16vl1__Z3fooPffi" -// CHECK-DAG: "_ZGVbN4ua16vl1__Z3fooPffi" -// CHECK-DAG: "_ZGVcM8ua16vl1__Z3fooPffi" -// CHECK-DAG: "_ZGVcN8ua16vl1__Z3fooPffi" -// CHECK-DAG: "_ZGVdM8ua16vl1__Z3fooPffi" -// CHECK-DAG: "_ZGVdN8ua16vl1__Z3fooPffi" -// CHECK-DAG: "_ZGVeM16ua16vl1__Z3fooPffi" -// CHECK-DAG: "_ZGVeN16ua16vl1__Z3fooPffi" - -// CHECK-DAG: "_ZGVbM4l8__Z5add_2Pf" -// CHECK-DAG: "_ZGVbN4l8__Z5add_2Pf" -// CHECK-DAG: "_ZGVcM8l8__Z5add_2Pf" -// CHECK-DAG: "_ZGVcN8l8__Z5add_2Pf" -// CHECK-DAG: "_ZGVdM8l8__Z5add_2Pf" -// CHECK-DAG: "_ZGVdN8l8__Z5add_2Pf" -// CHECK-DAG: "_ZGVeM16l8__Z5add_2Pf" -// CHECK-DAG: "_ZGVeN16l8__Z5add_2Pf" +// CHECK-DAG: "_ZGVbM4ua16vl__Z3fooPffi" +// CHECK-DAG: "_ZGVbN4ua16vl__Z3fooPffi" +// CHECK-DAG: "_ZGVcM8ua16vl__Z3fooPffi" +// CHECK-DAG: "_ZGVcN8ua16vl__Z3fooPffi" +// CHECK-DAG: "_ZGVdM8ua16vl__Z3fooPffi" +// CHECK-DAG: "_ZGVdN8ua16vl__Z3fooPffi" +// CHECK-DAG: "_ZGVeM16ua16vl__Z3fooPffi" +// CHECK-DAG: "_ZGVeN16ua16vl__Z3fooPffi" + +// CHECK-DAG: "_ZGVbM4l32__Z5add_2Pf" +// CHECK-DAG: "_ZGVbN4l32__Z5add_2Pf" +// CHECK-DAG: "_ZGVcM8l32__Z5add_2Pf" +// CHECK-DAG: "_ZGVcN8l32__Z5add_2Pf" +// CHECK-DAG: "_ZGVdM8l32__Z5add_2Pf" +// CHECK-DAG: "_ZGVdN8l32__Z5add_2Pf" +// CHECK-DAG: "_ZGVeM16l32__Z5add_2Pf" +// CHECK-DAG: "_ZGVeN16l32__Z5add_2Pf" // CHECK-DAG: "_ZGVbM32v__Z5add_2Pf" // CHECK-DAG: "_ZGVcM32v__Z5add_2Pf" // CHECK-DAG: "_ZGVdM32v__Z5add_2Pf"