r304781 - [ARM] Add support for target("arm") and target("thumb").
Author: fhahn Date: Tue Jun 6 04:26:15 2017 New Revision: 304781 URL: http://llvm.org/viewvc/llvm-project?rev=304781&view=rev Log: [ARM] Add support for target("arm") and target("thumb"). Summary: This patch adds support for the target("arm") and target("thumb") attributes, which can be used to force the compiler to generated ARM or Thumb code for a function. In LLVM, ARM or Thumb code generation can be controlled by the thumb-mode target feature. But GCC already uses target("arm") and target("thumb"), so we have to substitute "arm" with -thumb-mode and "thumb" with +thumb-mode. Reviewers: echristo, pcc, kristof.beyls Reviewed By: echristo Subscribers: ahatanak, aemerson, javed.absar, kristof.beyls, cfe-commits Differential Revision: https://reviews.llvm.org/D33721 Added: cfe/trunk/test/CodeGen/arm-target-attr.c Modified: cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304781&r1=304780&r2=304781&view=diff == --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Tue Jun 6 04:26:15 2017 @@ -5438,7 +5438,17 @@ public: if (Feature[0] == '+') Features[Feature.drop_front(1)] = true; -return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); +// Convert user-provided arm and thumb GNU target attributes to +// [-|+]thumb-mode target features respectively. +std::vector UpdatedFeaturesVec(FeaturesVec); +for (auto &Feature : UpdatedFeaturesVec) { + if (Feature.compare("+arm") == 0) +Feature = "-thumb-mode"; + else if (Feature.compare("+thumb") == 0) +Feature = "+thumb-mode"; +} + +return TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeaturesVec); } bool handleTargetFeatures(std::vector &Features, Added: cfe/trunk/test/CodeGen/arm-target-attr.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-target-attr.c?rev=304781&view=auto == --- cfe/trunk/test/CodeGen/arm-target-attr.c (added) +++ cfe/trunk/test/CodeGen/arm-target-attr.c Tue Jun 6 04:26:15 2017 @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple thumb-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKPOS %s +// RUN: %clang_cc1 -triple thumb-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKNEG %s +// RUN: %clang_cc1 -triple arm-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKPOS %s +// RUN: %clang_cc1 -triple arm-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix CHECKNEG %s + +__attribute__((target("arm"))) void test_target_arm() { + // CHECKPOS: define void @test_target_arm() [[ARM_ATTRS:#[0-9]+]] + // CHECKNEG: define void @test_target_arm() [[ARM_ATTRS:#[0-9]+]] +} + +__attribute__((target("thumb"))) void test_target_thumb() { + // CHECKPOS: define void @test_target_thumb() [[THUMB_ATTRS:#[0-9]+]] + // CHECKNEG: define void @test_target_thumb() [[THUMB_ATTRS:#[0-9]+]] +} + +// CHECKPOS: attributes [[ARM_ATTRS]] = { {{.*}} "target-features"="{{.*}}-thumb-mode{{.*}}" +// CHECKPOS: attributes [[THUMB_ATTRS]] = { {{.*}} "target-features"="{{.*}}+thumb-mode{{.*}}" +// CHECKNEG-NOT: attributes [[ARM_ATTRS]] = { {{.*}} "target-features"="{{.*}}+thumb-mode{{.*}}" +// CHECKNEG-NOT: attributes [[THUMB_ATTRS]] = { {{.*}} "target-features"="{{.*}}-thumb-mode{{.*}}" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r304897 - [CodeGen] Add thumb-mode to target-features for arm/thumb triples.
Author: fhahn Date: Wed Jun 7 06:50:45 2017 New Revision: 304897 URL: http://llvm.org/viewvc/llvm-project?rev=304897&view=rev Log: [CodeGen] Add thumb-mode to target-features for arm/thumb triples. Summary: The thumb-mode target feature is used to force Thumb or ARM code generation on a per-function basis. Explicitly adding +thumb-mode to functions for thumbxx triples enables mixed ARM/Thumb code generation in places where compilation units with thumbxx and armxx triples are merged together (e.g. the IR linker or LTO). For armxx triples, -thumb-mode is added in a similar fashion. Reviewers: echristo, t.p.northover, kristof.beyls, rengolin Reviewed By: echristo Subscribers: rinon, aemerson, mehdi_amini, javed.absar, cfe-commits Differential Revision: https://reviews.llvm.org/D33448 Added: cfe/trunk/test/CodeGen/arm-thumb-mode-target-feature.c Modified: cfe/trunk/lib/Basic/Targets.cpp cfe/trunk/test/CodeGen/arm-long-calls.c cfe/trunk/test/CodeGen/arm-no-movt.c cfe/trunk/test/CodeGen/arm-target-features.c Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304897&r1=304896&r2=304897&view=diff == --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun 7 06:50:45 2017 @@ -5442,6 +5442,13 @@ public: if (Feature[0] == '+') Features[Feature.drop_front(1)] = true; +// Enable or disable thumb-mode explicitly per function to enable mixed +// ARM and Thumb code generation. +if (isThumb()) + Features["thumb-mode"] = true; +else + Features["thumb-mode"] = false; + // Convert user-provided arm and thumb GNU target attributes to // [-|+]thumb-mode target features respectively. std::vector UpdatedFeaturesVec(FeaturesVec); Modified: cfe/trunk/test/CodeGen/arm-long-calls.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-long-calls.c?rev=304897&r1=304896&r2=304897&view=diff == --- cfe/trunk/test/CodeGen/arm-long-calls.c (original) +++ cfe/trunk/test/CodeGen/arm-long-calls.c Wed Jun 7 06:50:45 2017 @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -triple thumbv7-apple-ios5 -target-feature +long-calls -emit-llvm -o - %s | FileCheck -check-prefix=LONGCALL %s // RUN: %clang_cc1 -triple thumbv7-apple-ios5 -emit-llvm -o - %s | FileCheck -check-prefix=NOLONGCALL %s -// LONGCALL: attributes #0 = { {{.*}} "target-features"="+long-calls" -// NOLONGCALL-NOT: attributes #0 = { {{.*}} "target-features"="+long-calls" +// LONGCALL: attributes #0 = { {{.*}} "target-features"="+long-calls,+thumb-mode" +// NOLONGCALL-NOT: attributes #0 = { {{.*}} "target-features"="+long-calls,+thumb-mode" int foo1(int a) { return a; } Modified: cfe/trunk/test/CodeGen/arm-no-movt.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-no-movt.c?rev=304897&r1=304896&r2=304897&view=diff == --- cfe/trunk/test/CodeGen/arm-no-movt.c (original) +++ cfe/trunk/test/CodeGen/arm-no-movt.c Wed Jun 7 06:50:45 2017 @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -triple thumbv7-apple-ios5 -target-feature +no-movt -emit-llvm -o - %s | FileCheck -check-prefix=NO-MOVT %s // RUN: %clang_cc1 -triple thumbv7-apple-ios5 -emit-llvm -o - %s | FileCheck -check-prefix=MOVT %s -// NO-MOVT: attributes #0 = { {{.*}} "target-features"="+no-movt" -// MOVT-NOT: attributes #0 = { {{.*}} "target-features"="+no-movt" +// NO-MOVT: attributes #0 = { {{.*}} "target-features"="+no-movt,+thumb-mode" +// MOVT-NOT: attributes #0 = { {{.*}} "target-features"="+no-movt,+thumb-mode" int foo1(int a) { return a; } Modified: cfe/trunk/test/CodeGen/arm-target-features.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-target-features.c?rev=304897&r1=304896&r2=304897&view=diff == --- cfe/trunk/test/CodeGen/arm-target-features.c (original) +++ cfe/trunk/test/CodeGen/arm-target-features.c Wed Jun 7 06:50:45 2017 @@ -1,65 +1,63 @@ // REQUIRES: arm-registered-target // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu cortex-a8 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3 -// CHECK-VFP3: "target-features"="+dsp,+neon,+vfp3" - - -// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-a9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-FP16 -// CHECK-VFP3-FP16: "target-features"="+dsp,+fp16,+neon,+vfp3" +// CHECK-VFP3: "target-features"="+dsp,+neon,+thumb-mode // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu cortex-a5 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4 -// CHECK-VFP4: "target-features"="+dsp,+neon,+vfp4" +// CHECK-VFP4: "target-features"="+dsp,+neon,+thumb-mode,+vfp4"
r305312 - Align definition of DW_OP_plus with DWARF spec [2/3]
Author: fhahn Date: Tue Jun 13 13:06:15 2017 New Revision: 305312 URL: http://llvm.org/viewvc/llvm-project?rev=305312&view=rev Log: Align definition of DW_OP_plus with DWARF spec [2/3] Summary: This patch is part of 3 patches that together form a single patch, but must be introduced in stages in order not to break things. The way that LLVM interprets DW_OP_plus in DIExpression nodes is basically that of the DW_OP_plus_uconst operator since LLVM expects an unsigned constant operand. This unnecessarily restricts the DW_OP_plus operator, preventing it from being used to describe the evaluation of runtime values on the expression stack. These patches try to align the semantics of DW_OP_plus and DW_OP_minus with that of the DWARF definition, which pops two elements off the expression stack, performs the operation and pushes the result back on the stack. This is done in three stages: • The first patch (LLVM) adds support for DW_OP_plus_uconst and changes all uses (and tests) of DW_OP_plus to use DW_OP_plus_uconst. • The second patch (Clang) contains changes to use DW_OP_plus_uconst instead of DW_OP_plus. • The third patch (LLVM) changes the semantics of DW_OP_plus to be in line with it’s DWARF meaning. It also does this for DW_OP_minus. Patch by Sander de Smalen. Reviewers: echristo, pcc, aprantl Reviewed By: aprantl Subscribers: aprantl, cfe-commits Differential Revision: https://reviews.llvm.org/D33893 Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=305312&r1=305311&r2=305312&view=diff == --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Jun 13 13:06:15 2017 @@ -3490,13 +3490,13 @@ void CGDebugInfo::EmitDeclare(const VarD if (VD->hasAttr()) { // Here, we need an offset *into* the alloca. CharUnits offset = CharUnits::fromQuantity(32); - Expr.push_back(llvm::dwarf::DW_OP_plus); + Expr.push_back(llvm::dwarf::DW_OP_plus_uconst); // offset of __forwarding field offset = CGM.getContext().toCharUnitsFromBits( CGM.getTarget().getPointerWidth(0)); Expr.push_back(offset.getQuantity()); Expr.push_back(llvm::dwarf::DW_OP_deref); - Expr.push_back(llvm::dwarf::DW_OP_plus); + Expr.push_back(llvm::dwarf::DW_OP_plus_uconst); // offset of x field offset = CGM.getContext().toCharUnitsFromBits(XOffset); Expr.push_back(offset.getQuantity()); @@ -3605,17 +3605,17 @@ void CGDebugInfo::EmitDeclareOfBlockDecl SmallVector addr; addr.push_back(llvm::dwarf::DW_OP_deref); - addr.push_back(llvm::dwarf::DW_OP_plus); + addr.push_back(llvm::dwarf::DW_OP_plus_uconst); addr.push_back(offset.getQuantity()); if (isByRef) { addr.push_back(llvm::dwarf::DW_OP_deref); -addr.push_back(llvm::dwarf::DW_OP_plus); +addr.push_back(llvm::dwarf::DW_OP_plus_uconst); // offset of __forwarding field offset = CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0)); addr.push_back(offset.getQuantity()); addr.push_back(llvm::dwarf::DW_OP_deref); -addr.push_back(llvm::dwarf::DW_OP_plus); +addr.push_back(llvm::dwarf::DW_OP_plus_uconst); // offset of x field offset = CGM.getContext().toCharUnitsFromBits(XOffset); addr.push_back(offset.getQuantity()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r321183 - [Complex] Don't use __div?c3 when building with fast-math.
Author: fhahn Date: Wed Dec 20 07:50:52 2017 New Revision: 321183 URL: http://llvm.org/viewvc/llvm-project?rev=321183&view=rev Log: [Complex] Don't use __div?c3 when building with fast-math. Summary: Plant an inline version of "((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))" instead. Patch by Paul Walker. Reviewed By: hfinkel Differential Revision: https://reviews.llvm.org/D40299 Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp cfe/trunk/test/CodeGen/complex-math.c Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=321183&r1=321182&r2=321183&view=diff == --- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Wed Dec 20 07:50:52 2017 @@ -761,15 +761,16 @@ ComplexPairTy ComplexExprEmitter::EmitBi llvm::Value *LHSr = Op.LHS.first, *LHSi = Op.LHS.second; llvm::Value *RHSr = Op.RHS.first, *RHSi = Op.RHS.second; - llvm::Value *DSTr, *DSTi; if (LHSr->getType()->isFloatingPointTy()) { -// If we have a complex operand on the RHS, we delegate to a libcall to -// handle all of the complexities and minimize underflow/overflow cases. +// If we have a complex operand on the RHS and FastMath is not allowed, we +// delegate to a libcall to handle all of the complexities and minimize +// underflow/overflow cases. When FastMath is allowed we construct the +// divide inline using the same algorithm as for integer operands. // // FIXME: We would be able to avoid the libcall in many places if we // supported imaginary types in addition to complex types. -if (RHSi) { +if (RHSi && !CGF.getLangOpts().FastMath) { BinOpInfo LibCallOp = Op; // If LHS was a real, supply a null imaginary part. if (!LHSi) @@ -791,11 +792,31 @@ ComplexPairTy ComplexExprEmitter::EmitBi case llvm::Type::FP128TyID: return EmitComplexBinOpLibCall("__divtc3", LibCallOp); } -} -assert(LHSi && "Can have at most one non-complex operand!"); +} else if (RHSi) { + if (!LHSi) +LHSi = llvm::Constant::getNullValue(RHSi->getType()); + + // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) + llvm::Value *AC = Builder.CreateFMul(LHSr, RHSr); // a*c + llvm::Value *BD = Builder.CreateFMul(LHSi, RHSi); // b*d + llvm::Value *ACpBD = Builder.CreateFAdd(AC, BD); // ac+bd -DSTr = Builder.CreateFDiv(LHSr, RHSr); -DSTi = Builder.CreateFDiv(LHSi, RHSr); + llvm::Value *CC = Builder.CreateFMul(RHSr, RHSr); // c*c + llvm::Value *DD = Builder.CreateFMul(RHSi, RHSi); // d*d + llvm::Value *CCpDD = Builder.CreateFAdd(CC, DD); // cc+dd + + llvm::Value *BC = Builder.CreateFMul(LHSi, RHSr); // b*c + llvm::Value *AD = Builder.CreateFMul(LHSr, RHSi); // a*d + llvm::Value *BCmAD = Builder.CreateFSub(BC, AD); // bc-ad + + DSTr = Builder.CreateFDiv(ACpBD, CCpDD); + DSTi = Builder.CreateFDiv(BCmAD, CCpDD); +} else { + assert(LHSi && "Can have at most one non-complex operand!"); + + DSTr = Builder.CreateFDiv(LHSr, RHSr); + DSTi = Builder.CreateFDiv(LHSi, RHSr); +} } else { assert(Op.LHS.second && Op.RHS.second && "Both operands of integer complex operators must be complex!"); Modified: cfe/trunk/test/CodeGen/complex-math.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/complex-math.c?rev=321183&r1=321182&r2=321183&view=diff == --- cfe/trunk/test/CodeGen/complex-math.c (original) +++ cfe/trunk/test/CodeGen/complex-math.c Wed Dec 20 07:50:52 2017 @@ -5,6 +5,7 @@ // RUN %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM // RUN: %clang_cc1 %s -O1 -emit-llvm -triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF // RUN: %clang_cc1 %s -O1 -emit-llvm -triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s --check-prefix=ARM7K +// RUN: %clang_cc1 %s -O1 -emit-llvm -triple aarch64-unknown-unknown -ffast-math -o - | FileCheck %s --check-prefix=AARCH64-FASTMATH float _Complex add_float_rr(float a, float b) { // X86-LABEL: @add_float_rr( @@ -128,6 +129,29 @@ float _Complex div_float_rc(float a, flo // X86-NOT: fdiv // X86: call {{.*}} @__divsc3( // X86: ret + + // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD)) + // AARCH64-FASTMATH-LABEL: @div_float_rc(float %a, [2 x float] %b.coerce) + // A = a + // B = 0 + // AARCH64-FASTMATH: [[C:%.*]] = extractvalue [2 x float] %b.coerce, 0 + // AARCH64-FASTMATH: [[D:%.*]] = extractvalue [2 x float] %b.coerce, 1 + // + // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float [[C]], %a + // BD = 0 + // ACpBD = AC + // + // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float [[C]], [[C]] + // AARC
r358753 - [LTO] Add plumbing to save stats during LTO on Darwin.
Author: fhahn Date: Fri Apr 19 05:36:41 2019 New Revision: 358753 URL: http://llvm.org/viewvc/llvm-project?rev=358753&view=rev Log: [LTO] Add plumbing to save stats during LTO on Darwin. Gold and ld on Linux already support saving stats, but the infrastructure is missing on Darwin. Unfortunately it seems like the configuration from lib/LTO/LTO.cpp is not used. This patch adds a new LTOStatsFile option and adds plumbing in Clang to use it on Darwin, similar to the way remarks are handled. Currnetly the handling of LTO flags seems quite spread out, with a bunch of duplication. But I am not sure if there is an easy way to improve that? Reviewers: anemet, tejohnson, thegameg, steven_wu Reviewed By: steven_wu Differential Revision: https://reviews.llvm.org/D60516 Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=358753&r1=358752&r2=358753&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Fri Apr 19 05:36:41 2019 @@ -514,6 +514,14 @@ void darwin::Linker::ConstructJob(Compil } } + // Setup statistics file output. + SmallString<128> StatsFile = + getStatsFileName(Args, Output, Inputs[0], getToolChain().getDriver()); + if (!StatsFile.empty()) { +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back(Args.MakeArgString("-lto-stats-file=" + StatsFile.str())); + } + // It seems that the 'e' option is completely ignored for dynamic executables // (the default), and with static executables, the last one wins, as expected. Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r350718 - Revert r350648: "Fix clang for r350647: Missed a function rename"
Author: fhahn Date: Wed Jan 9 05:30:47 2019 New Revision: 350718 URL: http://llvm.org/viewvc/llvm-project?rev=350718&view=rev Log: Revert r350648: "Fix clang for r350647: Missed a function rename" The related commit r350647 breaks thread sanitizer on some macOS builders, e.g. http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/52725/ Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=350718&r1=350717&r2=350718&view=diff == --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Jan 9 05:30:47 2019 @@ -53,10 +53,9 @@ #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" #include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/Instrumentation.h" +#include "llvm/Transforms/Instrumentation/MemorySanitizer.h" #include "llvm/Transforms/Instrumentation/BoundsChecking.h" #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" -#include "llvm/Transforms/Instrumentation/MemorySanitizer.h" -#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" #include "llvm/Transforms/ObjCARC.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" @@ -306,7 +305,7 @@ static void addKernelMemorySanitizerPass static void addThreadSanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { - PM.add(createThreadSanitizerLegacyPassPass()); + PM.add(createThreadSanitizerPass()); } static void addDataFlowSanitizerPass(const PassManagerBuilder &Builder, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r330422 - [Driver] Support for -save-stats in AddGoldPlugin.
Author: fhahn Date: Fri Apr 20 05:50:10 2018 New Revision: 330422 URL: http://llvm.org/viewvc/llvm-project?rev=330422&view=rev Log: [Driver] Support for -save-stats in AddGoldPlugin. This patch updates AddGoldPlugin to pass stats-file to the Gold plugin, if -save-stats is passed. It also moves the save-stats option handling to a helper function tools::getStatsFileName. Reviewers: tejohnson, mehdi_amini, compnerd Reviewed By: tejohnson, compnerd Differential Revision: https://reviews.llvm.org/D45771 Modified: cfe/trunk/lib/Driver/ToolChains/Ananas.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp cfe/trunk/lib/Driver/ToolChains/CommonArgs.h cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp cfe/trunk/lib/Driver/ToolChains/Gnu.cpp cfe/trunk/test/Driver/save-stats.c Modified: cfe/trunk/lib/Driver/ToolChains/Ananas.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Ananas.cpp?rev=330422&r1=330421&r2=330422&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Ananas.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Ananas.cpp Fri Apr 20 05:50:10 2018 @@ -103,8 +103,11 @@ void ananas::Linker::ConstructJob(Compil {options::OPT_T_Group, options::OPT_e, options::OPT_s, options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); - if (D.isUsingLTO()) -AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D); + if (D.isUsingLTO()) { +assert(!Inputs.empty() && "Must have at least one input."); +AddGoldPlugin(ToolChain, Args, CmdArgs, Output, Inputs[0], + D.getLTOMode() == LTOK_Thin); + } AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=330422&r1=330421&r2=330422&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Apr 20 05:50:10 2018 @@ -4589,31 +4589,9 @@ void Clang::ConstructJob(Compilation &C, } // Setup statistics file output. - if (const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ)) { -StringRef SaveStats = A->getValue(); - -SmallString<128> StatsFile; -bool DoSaveStats = false; -if (SaveStats == "obj") { - if (Output.isFilename()) { -StatsFile.assign(Output.getFilename()); -llvm::sys::path::remove_filename(StatsFile); - } - DoSaveStats = true; -} else if (SaveStats == "cwd") { - DoSaveStats = true; -} else { - D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats; -} - -if (DoSaveStats) { - StringRef BaseName = llvm::sys::path::filename(Input.getBaseInput()); - llvm::sys::path::append(StatsFile, BaseName); - llvm::sys::path::replace_extension(StatsFile, "stats"); - CmdArgs.push_back(Args.MakeArgString(Twine("-stats-file=") + - StatsFile)); -} - } + SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D); + if (!StatsFile.empty()) +CmdArgs.push_back(Args.MakeArgString(Twine("-stats-file=") + StatsFile)); // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option // parser. Modified: cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp?rev=330422&r1=330421&r2=330422&view=diff == --- cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp Fri Apr 20 05:50:10 2018 @@ -75,8 +75,11 @@ void cloudabi::Linker::ConstructJob(Comp {options::OPT_T_Group, options::OPT_e, options::OPT_s, options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); - if (D.isUsingLTO()) -AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D); + if (D.isUsingLTO()) { +assert(!Inputs.empty() && "Must have at least one input."); +AddGoldPlugin(ToolChain, Args, CmdArgs, Output, Inputs[0], + D.getLTOMode() == LTOK_Thin); + } AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=330422&r1=330421&r2=330422&view=diff == --- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Fri Apr 20 05:50:10 2018 @@ -8,14 +8,14 @@ //===---
r336429 - [Driver,AArch64] Add support for -mcpu=native.
Author: fhahn Date: Fri Jul 6 03:49:59 2018 New Revision: 336429 URL: http://llvm.org/viewvc/llvm-project?rev=336429&view=rev Log: [Driver,AArch64] Add support for -mcpu=native. This patches adds support for passing -mcpu=native for AArch64. It will get turned into the host CPU name, before we get the target features. CPU = native is handled in a similar fashion in getAArch64MicroArchFetauresFromMtune and getAArch64TargetCPU already. Having a good test case for this is hard, as it depends on the host CPU of the machine running the test. But we can check that native has been replaced with something else. When cross-compiling, we will get a CPU name from the host architecture and get ` the clang compiler does not support '-mcpu=native'` as error message, which seems reasonable to me. Reviewers: rengolin, peter.smith, dlj, javed.absar, t.p.northover Reviewed By: peter.smith Tags: #clang Differential Revision: https://reviews.llvm.org/D48931 Modified: cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp cfe/trunk/test/Driver/aarch64-cpus.c Modified: cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp?rev=336429&r1=336428&r2=336429&view=diff == --- cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp Fri Jul 6 03:49:59 2018 @@ -69,6 +69,9 @@ static bool DecodeAArch64Mcpu(const Driv std::pair Split = Mcpu.split("+"); CPU = Split.first; + if (CPU == "native") +CPU = llvm::sys::getHostCPUName(); + if (CPU == "generic") { Features.push_back("+neon"); } else { Modified: cfe/trunk/test/Driver/aarch64-cpus.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-cpus.c?rev=336429&r1=336428&r2=336429&view=diff == --- cfe/trunk/test/Driver/aarch64-cpus.c (original) +++ cfe/trunk/test/Driver/aarch64-cpus.c Fri Jul 6 03:49:59 2018 @@ -15,6 +15,11 @@ // ARM64-GENERIC: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "generic" +// We cannot check much for -mcpu=native, but it should be replaced by either generic or a valid +// Arm cpu string, depending on the host. +// RUN: %clang -target arm64 -mcpu=native -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-NATIVE %s +// ARM64-NATIVE-NOT: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "native" + // RUN: %clang -target arm64-apple-darwin -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s // ARM64-DARWIN: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "cyclone" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r337255 - Temporarily revert r337226 "Restructure checking for, and warning on, lifetime extension."
Author: fhahn Date: Tue Jul 17 02:23:31 2018 New Revision: 337255 URL: http://llvm.org/viewvc/llvm-project?rev=337255&view=rev Log: Temporarily revert r337226 "Restructure checking for, and warning on, lifetime extension." This change breaks on ARM because pointers to clang::InitializedEntity are only 4 byte aligned and do not have 3 bits to store values. A possible solution would be to change the fields in clang::InitializedEntity to enforce a bigger alignment requirement. The error message is llvm/include/llvm/ADT/PointerIntPair.h:132:3: error: static_assert failed "PointerIntPair with integer size too large for pointer" static_assert(IntBits <= PtrTraits::NumLowBitsAvailable, include/llvm/ADT/PointerIntPair.h:73:13: note: in instantiation of template class 'llvm::PointerIntPairInfo >' requested here Value = Info::updateInt(Info::updatePointer(0, PtrVal), llvm/include/llvm/ADT/PointerIntPair.h:51:5: note: in instantiation of member function 'llvm::PointerIntPair, llvm::PointerIntPairInfo > >::setPointerAndInt' requested here setPointerAndInt(PtrVal, IntVal); ^ llvm/tools/clang/lib/Sema/SemaInit.cpp:6237:12: note: in instantiation of member function 'llvm::PointerIntPair, llvm::PointerIntPairInfo > >::PointerIntPair' requested here return {Entity, LK_Extended}; Full log here: http://lab.llvm.org:8011/builders/clang-cmake-armv7-global-isel/builds/1330 http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/1394 Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Initialization.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/Analysis/initializer.cpp cfe/trunk/test/CXX/drs/dr16xx.cpp cfe/trunk/test/CXX/drs/dr18xx.cpp cfe/trunk/test/CXX/special/class.copy/p11.0x.copy.cpp cfe/trunk/test/CXX/special/class.copy/p11.0x.move.cpp cfe/trunk/test/CXX/special/class.ctor/p5-0x.cpp cfe/trunk/test/CXX/temp/temp.param/p5.cpp cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp cfe/trunk/test/CodeGenCXX/temporaries.cpp cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp cfe/trunk/test/SemaCXX/constexpr-default-arg.cpp cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp cfe/trunk/test/SemaCXX/eval-crashes.cpp cfe/trunk/test/SemaCXX/member-init.cpp cfe/trunk/test/SemaCXX/warn-dangling-field.cpp cfe/trunk/www/cxx_dr_status.html Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=337255&r1=337254&r2=337255&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Jul 17 02:23:31 2018 @@ -272,7 +272,6 @@ def ShiftOpParentheses: DiagGroup<"shift def OverloadedShiftOpParentheses: DiagGroup<"overloaded-shift-op-parentheses">; def DanglingElse: DiagGroup<"dangling-else">; def DanglingField : DiagGroup<"dangling-field">; -def DanglingInitializerList : DiagGroup<"dangling-initializer-list">; def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; def ExpansionToDefined : DiagGroup<"expansion-to-defined">; def FlagEnum : DiagGroup<"flag-enum">; Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=337255&r1=337254&r2=337255&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 17 02:23:31 2018 @@ -2049,6 +2049,10 @@ def err_implied_std_initializer_list_not "not found; include ">; def err_malformed_std_initializer_list : Error< "std::initializer_list must be a class template with a single type parameter">; +def warn_dangling_std_initializer_list : Warning< + "array backing the initializer list will be destroyed at the end of " + "%select{the full-expression|the constructor}0">, + InGroup>; def err_auto_init_list_from_c : Error< "cannot use __auto_type with initializer list in C">; def err_auto_bitfield : Error< @@ -7840,39 +7844,13 @@ def warn_bind_ref_member_to_parameter : def warn_init_ptr_member_to_parameter_addr : Warning< "initializing pointer member %0 with the stack address of parameter %1">, InGroup; +def warn_bind_ref_member_to_temporary : Warning< + "binding reference %select{|subobject of }1member %0 to a temporary value">, + InGroup; def note_ref_or_ptr_member_declared_here : Note< "%select{reference|pointer}0 member declared here">; - -def err_bind_ref_member_to_temporary : Error< - "%select{r
Re: r337255 - Temporarily revert r337226 "Restructure checking for, and warning on, lifetime extension."
On 17/07/2018 23:29, Richard Smith wrote: Thank you. I added an 'alignas(8)' and reapplied in r337329. Great thank you very much! ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6f6e91d - [Matrix] Implement + and - operators for MatrixType.
Author: Florian Hahn Date: 2020-05-29T20:42:22+01:00 New Revision: 6f6e91d19337315548f550479f94cbc0af93c8fe URL: https://github.com/llvm/llvm-project/commit/6f6e91d19337315548f550479f94cbc0af93c8fe DIFF: https://github.com/llvm/llvm-project/commit/6f6e91d19337315548f550479f94cbc0af93c8fe.diff LOG: [Matrix] Implement + and - operators for MatrixType. This patch implements the + and - binary operators for values of MatrixType. It adds support for matrix +/- matrix, scalar +/- matrix and matrix +/- scalar. For the matrix, matrix case, the types must initially be structurally equivalent. For the scalar,matrix variants, the element type of the matrix must match the scalar type. Reviewers: rjmccall, anemet, Bigcheese, rsmith, martong Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D76793 Added: clang/test/CodeGen/matrix-type-operators.c clang/test/CodeGenCXX/matrix-type-operators.cpp clang/test/Sema/matrix-type-operators.c clang/test/SemaCXX/matrix-type-operators.cpp Modified: clang/include/clang/AST/Type.h clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGExprScalar.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaOverload.cpp llvm/include/llvm/IR/MatrixBuilder.h Removed: diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index ed31dea925f3..3cdce1fbfe53 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -2050,7 +2050,8 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { bool isComplexIntegerType() const;// GCC _Complex integer type. bool isVectorType() const;// GCC vector type. bool isExtVectorType() const; // Extended vector type. - bool isConstantMatrixType() const;// Matrix type. + bool isMatrixType() const;// Matrix type. + bool isConstantMatrixType() const;// Constant matrix type. bool isDependentAddressSpaceType() const; // value-dependent address space qualifier bool isObjCObjectPointerType() const; // pointer to ObjC object bool isObjCRetainableType() const;// ObjC object or block pointer @@ -6744,6 +6745,10 @@ inline bool Type::isExtVectorType() const { return isa(CanonicalType); } +inline bool Type::isMatrixType() const { + return isa(CanonicalType); +} + inline bool Type::isConstantMatrixType() const { return isa(CanonicalType); } diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 594c6e03aa38..03977d2c94f9 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11205,6 +11205,11 @@ class Sema final { QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, SourceLocation Loc); + /// Type checking for matrix binary operators. + QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, + bool IsCompAssign); + bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); bool isLaxVectorConversion(QualType srcType, QualType destType); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 346c429f663e..84620b1f7d81 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -37,6 +37,7 @@ #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/IntrinsicsPowerPC.h" +#include "llvm/IR/MatrixBuilder.h" #include "llvm/IR/Module.h" #include @@ -3536,6 +3537,11 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) { } } + if (op.Ty->isConstantMatrixType()) { +llvm::MatrixBuilder MB(Builder); +return MB.CreateAdd(op.LHS, op.RHS); + } + if (op.Ty->isUnsignedIntegerType() && CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow) && !CanElideOverflowCheck(CGF.getContext(), op)) @@ -3720,6 +3726,11 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) { } } +if (op.Ty->isConstantMatrixType()) { + llvm::MatrixBuilder MB(Builder); + return MB.CreateSub(op.LHS, op.RHS); +} + if (op.Ty->isUnsignedIntegerType() && CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow) && !CanElideOverflowCheck(CGF.getContext(), op)) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 63f71d81e047..f4e8c2d09edc 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10243,6 +10243,11 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS, return compType; } + if (LHS.get()->getType()->isConstantMatrixType() || + RHS.get()->getType()->isConstantMatrixType()) { +return CheckMatrixElementwiseOperands(LHS,
[clang] 8f3f88d - [Matrix] Implement matrix index expressions ([][]).
Author: Florian Hahn Date: 2020-06-01T20:08:49+01:00 New Revision: 8f3f88d2f50d97011bf48ccc507bef033715e566 URL: https://github.com/llvm/llvm-project/commit/8f3f88d2f50d97011bf48ccc507bef033715e566 DIFF: https://github.com/llvm/llvm-project/commit/8f3f88d2f50d97011bf48ccc507bef033715e566.diff LOG: [Matrix] Implement matrix index expressions ([][]). This patch implements matrix index expressions (matrix[RowIdx][ColumnIdx]). It does so by introducing a new MatrixSubscriptExpr(Base, RowIdx, ColumnIdx). MatrixSubscriptExprs are built in 2 steps in ActOnMatrixSubscriptExpr. First, if the base of a subscript is of matrix type, we create a incomplete MatrixSubscriptExpr(base, idx, nullptr). Second, if the base is an incomplete MatrixSubscriptExpr, we create a complete MatrixSubscriptExpr(base->getBase(), base->getRowIdx(), idx) Similar to vector elements, it is not possible to take the address of a MatrixSubscriptExpr. For CodeGen, a new MatrixElt type is added to LValue, which is very similar to VectorElt. The only difference is that we may need to cast the type of the base from an array to a vector type when accessing it. Reviewers: rjmccall, anemet, Bigcheese, rsmith, martong Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D76791 Added: clang/test/CodeGenObjC/matrix-type-operators.m clang/test/SemaObjC/matrix-type-operators.m Modified: clang/include/clang/AST/ASTContext.h clang/include/clang/AST/BuiltinTypes.def clang/include/clang/AST/ComputeDependence.h clang/include/clang/AST/Expr.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/AST/Stmt.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Basic/Specifiers.h clang/include/clang/Basic/StmtNodes.td clang/include/clang/Sema/Initialization.h clang/include/clang/Sema/Sema.h clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ComputeDependence.cpp clang/lib/AST/Expr.cpp clang/lib/AST/ExprClassification.cpp clang/lib/AST/ExprConstant.cpp clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/NSAPI.cpp clang/lib/AST/StmtPrinter.cpp clang/lib/AST/StmtProfile.cpp clang/lib/AST/TextNodeDumper.cpp clang/lib/AST/Type.cpp clang/lib/AST/TypeLoc.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprScalar.cpp clang/lib/CodeGen/CGValue.h clang/lib/CodeGen/CodeGenFunction.h clang/lib/Sema/SemaCast.cpp clang/lib/Sema/SemaExceptionSpec.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTCommon.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/test/CodeGen/matrix-type-operators.c clang/test/CodeGenCXX/matrix-type-operators.cpp clang/test/Sema/matrix-type-operators.c clang/test/SemaCXX/matrix-type-operators.cpp clang/tools/libclang/CXCursor.cpp llvm/include/llvm/IR/MatrixBuilder.h Removed: diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index a5bb9a34c2fb..4463ffc1a9de 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -978,6 +978,7 @@ class ASTContext : public RefCountedBase { #include "clang/Basic/OpenCLImageTypes.def" CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy; CanQualType OCLQueueTy, OCLReserveIDTy; + CanQualType IncompleteMatrixIdxTy; CanQualType OMPArraySectionTy, OMPArrayShapingTy, OMPIteratorTy; #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ CanQualType Id##Ty; diff --git a/clang/include/clang/AST/BuiltinTypes.def b/clang/include/clang/AST/BuiltinTypes.def index f8eb4ec19c8f..5112382da832 100644 --- a/clang/include/clang/AST/BuiltinTypes.def +++ b/clang/include/clang/AST/BuiltinTypes.def @@ -310,6 +310,9 @@ PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy) // context. PLACEHOLDER_TYPE(ARCUnbridgedCast, ARCUnbridgedCastTy) +// A placeholder type for incomplete matrix index expressions. +PLACEHOLDER_TYPE(IncompleteMatrixIdx, IncompleteMatrixIdxTy) + // A placeholder type for OpenMP array sections. PLACEHOLDER_TYPE(OMPArraySection, OMPArraySectionTy) diff --git a/clang/include/clang/AST/ComputeDependence.h b/clang/include/clang/AST/ComputeDependence.h index ab742c9b70dd..ac2daf9eb95a 100644 --- a/clang/include/clang/AST/ComputeDependence.h +++ b/clang/include/clang/AST/ComputeDependence.h @@ -28,6 +28,7 @@ class ParenExpr; class UnaryOperator; class UnaryExprOrTypeTraitExpr; class ArraySubscriptExpr; +class MatrixSubscriptExpr; class CompoundLiteralExpr; class CastExpr; class BinaryOperator; @@ -108,6 +109,7 @@ ExprDependence computeDependence(ParenExpr *E); ExprDependence computeDependence(U
[clang] a6a42df - [Sema] Fix -Wunused-variable in CreateBuiltinMatrixSubscriptExpr (NFC).
Author: Florian Hahn Date: 2020-06-02T10:45:30+01:00 New Revision: a6a42df506ca93df69725f732c396050060f026f URL: https://github.com/llvm/llvm-project/commit/a6a42df506ca93df69725f732c396050060f026f DIFF: https://github.com/llvm/llvm-project/commit/a6a42df506ca93df69725f732c396050060f026f.diff LOG: [Sema] Fix -Wunused-variable in CreateBuiltinMatrixSubscriptExpr (NFC). Added: Modified: clang/lib/Sema/SemaExpr.cpp Removed: diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index e177c9d4adec..2221f98b943a 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4737,6 +4737,7 @@ ExprResult Sema::CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, bool ConversionOk = tryConvertToTy(*this, Context.getSizeType(), &ConvExpr); assert(ConversionOk && "should be able to convert any integer type to size type"); +(void)ConversionOk; return ConvExpr.get(); }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 338be9c - [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.
Author: Florian Hahn Date: 2020-04-07T14:01:55+01:00 New Revision: 338be9c59527c3d172f64e8861bcbb472297d52d URL: https://github.com/llvm/llvm-project/commit/338be9c59527c3d172f64e8861bcbb472297d52d DIFF: https://github.com/llvm/llvm-project/commit/338be9c59527c3d172f64e8861bcbb472297d52d.diff LOG: [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops. Currently Clang does not respect -fno-unroll-loops during LTO. During D76916 it was suggested to respect -fno-unroll-loops on a TU basis. This patch uses the existing llvm.loop.unroll.disable metadata to disable loop unrolling explicitly for each loop in the TU if unrolling is disabled. This should ensure that loops from TUs compiled with -fno-unroll-loops are skipped by the unroller during LTO. This also means that if a loop from a TU with -fno-unroll-loops gets inlined into a TU without this option, the loop won't be unrolled. Due to the fact that some transforms might drop loop metadata, there potentially are cases in which we still unroll loops from TUs with -fno-unroll-loops. I think we should fix those issues rather than introducing a function attribute to disable loop unrolling during LTO. Improving the metadata handling will benefit other use cases, like various loop pragmas, too. And it is an improvement to clang completely ignoring -fno-unroll-loops during LTO. If that direction looks good, we can use a similar approach to also respect -fno-vectorize during LTO, at least for LoopVectorize. In the future, this might also allow us to remove the UnrollLoops option LLVM's PassManagerBuilder. Reviewers: Meinersbur, hfinkel, dexonsmith, tejohnson Reviewed By: Meinersbur, tejohnson Differential Revision: https://reviews.llvm.org/D77058 Added: clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp Modified: clang/lib/CodeGen/CGLoopInfo.cpp clang/lib/CodeGen/CGLoopInfo.h clang/lib/CodeGen/CGStmt.cpp clang/test/CodeGenCXX/pragma-unroll.cpp Removed: diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp index 5addf1976168..78da72eda0cf 100644 --- a/clang/lib/CodeGen/CGLoopInfo.cpp +++ b/clang/lib/CodeGen/CGLoopInfo.cpp @@ -10,6 +10,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" #include "clang/AST/Expr.h" +#include "clang/Basic/CodeGenOptions.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Constants.h" @@ -573,6 +574,7 @@ void LoopInfoStack::push(BasicBlock *Header, const llvm::DebugLoc &StartLoc, } void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx, + const clang::CodeGenOptions &CGOpts, ArrayRef Attrs, const llvm::DebugLoc &StartLoc, const llvm::DebugLoc &EndLoc) { @@ -753,6 +755,14 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx, } } + if (CGOpts.OptimizationLevel > 0) +// Disable unrolling for the loop, if unrolling is disabled (via +// -fno-unroll-loops) and no pragmas override the decision. +if (!CGOpts.UnrollLoops && +(StagedAttrs.UnrollEnable == LoopAttributes::Unspecified && + StagedAttrs.UnrollCount == 0)) + setUnrollState(LoopAttributes::Disable); + /// Stage the attributes. push(Header, StartLoc, EndLoc); } diff --git a/clang/lib/CodeGen/CGLoopInfo.h b/clang/lib/CodeGen/CGLoopInfo.h index 5abcf37c5433..e379c64c99a8 100644 --- a/clang/lib/CodeGen/CGLoopInfo.h +++ b/clang/lib/CodeGen/CGLoopInfo.h @@ -29,6 +29,7 @@ class MDNode; namespace clang { class Attr; class ASTContext; +class CodeGenOptions; namespace CodeGen { /// Attributes that may be specified on loops. @@ -202,6 +203,7 @@ class LoopInfoStack { /// Begin a new structured loop. Stage attributes from the Attrs list. /// The staged attributes are applied to the loop and then cleared. void push(llvm::BasicBlock *Header, clang::ASTContext &Ctx, +const clang::CodeGenOptions &CGOpts, llvm::ArrayRef Attrs, const llvm::DebugLoc &StartLoc, const llvm::DebugLoc &EndLoc); diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 85c3bcca0647..ceecbd4dc137 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -728,8 +728,8 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, EmitBlock(LoopHeader.getBlock()); const SourceRange &R = S.getSourceRange(); - LoopStack.push(LoopHeader.getBlock(), CGM.getContext(), WhileAttrs, - SourceLocToDebugLoc(R.getBegin()), + LoopStack.push(LoopHeader.getBlock(), CGM.getContext(), CGM.getCodeGenOpts(), + WhileAttrs, SourceLocToDebugLoc(R.getBegin()), SourceLocToDebugLoc(R.getEnd())); // Create an exit block for when the condition fails, which will @@ -830,7 +830,7 @@ void CodeGenFun
[clang] a7c6bec - [Sema] Remove unused matrix_begin/end helpers (NFC).
Author: Florian Hahn Date: 2020-06-04T11:29:01+01:00 New Revision: a7c6bec228ca28e9eee77433292ac86d77b67790 URL: https://github.com/llvm/llvm-project/commit/a7c6bec228ca28e9eee77433292ac86d77b67790 DIFF: https://github.com/llvm/llvm-project/commit/a7c6bec228ca28e9eee77433292ac86d77b67790.diff LOG: [Sema] Remove unused matrix_begin/end helpers (NFC). The matrix_types() helper returning an iterator range is used instead. Added: Modified: clang/lib/Sema/SemaOverload.cpp Removed: diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 9739e1511039..11b6e40e8cd4 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7749,8 +7749,6 @@ class BuiltinCandidateTypeSet { iterator vector_end() { return VectorTypes.end(); } llvm::iterator_range matrix_types() { return MatrixTypes; } - iterator matrix_begin() { return MatrixTypes.begin(); } - iterator matrix_end() { return MatrixTypes.end(); } bool containsMatrixType(QualType Ty) const { return MatrixTypes.count(Ty); } bool hasNonRecordTypes() { return HasNonRecordTypes; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 714e84b - [SemaOverload] Use iterator_range to iterate over VectorTypes (NFC).
Author: Florian Hahn Date: 2020-06-04T20:47:16+01:00 New Revision: 714e84be4615d6e1195f2798c0c3c8c54017dd5f URL: https://github.com/llvm/llvm-project/commit/714e84be4615d6e1195f2798c0c3c8c54017dd5f DIFF: https://github.com/llvm/llvm-project/commit/714e84be4615d6e1195f2798c0c3c8c54017dd5f.diff LOG: [SemaOverload] Use iterator_range to iterate over VectorTypes (NFC). We can simplify the code a bit by using iterator_range instead of plain iterators. Matrix type support here (added in 6f6e91d19337) already uses an iterator_range. Reviewers: rjmccall, arphaman, jfb, Bigcheese Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D81138 Added: Modified: clang/lib/Sema/SemaOverload.cpp Removed: diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 11b6e40e8cd4..f3ac2036cb0d 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7745,8 +7745,7 @@ class BuiltinCandidateTypeSet { /// enumeration_end - Past the last enumeration type found; iterator enumeration_end() { return EnumerationTypes.end(); } - iterator vector_begin() { return VectorTypes.begin(); } - iterator vector_end() { return VectorTypes.end(); } + llvm::iterator_range vector_types() { return VectorTypes; } llvm::iterator_range matrix_types() { return MatrixTypes; } @@ -8292,13 +8291,8 @@ class BuiltinOperatorOverloadBuilder { } // Extension: We also add these operators for vector types. -for (BuiltinCandidateTypeSet::iterator - Vec = CandidateTypes[0].vector_begin(), - VecEnd = CandidateTypes[0].vector_end(); - Vec != VecEnd; ++Vec) { - QualType VecTy = *Vec; +for (QualType VecTy : CandidateTypes[0].vector_types()) S.AddBuiltinCandidate(&VecTy, Args, CandidateSet); -} } // C++ [over.built]p8: @@ -8332,13 +8326,8 @@ class BuiltinOperatorOverloadBuilder { } // Extension: We also add this operator for vector types. -for (BuiltinCandidateTypeSet::iterator - Vec = CandidateTypes[0].vector_begin(), - VecEnd = CandidateTypes[0].vector_end(); - Vec != VecEnd; ++Vec) { - QualType VecTy = *Vec; +for (QualType VecTy : CandidateTypes[0].vector_types()) S.AddBuiltinCandidate(&VecTy, Args, CandidateSet); -} } // C++ [over.match.oper]p16: @@ -8569,18 +8558,11 @@ class BuiltinOperatorOverloadBuilder { // Extension: Add the binary operators ==, !=, <, <=, >=, >, *, /, and the // conditional operator for vector types. -for (BuiltinCandidateTypeSet::iterator - Vec1 = CandidateTypes[0].vector_begin(), - Vec1End = CandidateTypes[0].vector_end(); - Vec1 != Vec1End; ++Vec1) { - for (BuiltinCandidateTypeSet::iterator -Vec2 = CandidateTypes[1].vector_begin(), - Vec2End = CandidateTypes[1].vector_end(); - Vec2 != Vec2End; ++Vec2) { -QualType LandR[2] = { *Vec1, *Vec2 }; +for (QualType Vec1Ty : CandidateTypes[0].vector_types()) + for (QualType Vec2Ty : CandidateTypes[1].vector_types()) { +QualType LandR[2] = {Vec1Ty, Vec2Ty}; S.AddBuiltinCandidate(LandR, Args, CandidateSet); } -} } /// Add binary operator overloads for each candidate matrix type M1, M2: @@ -8861,30 +8843,23 @@ class BuiltinOperatorOverloadBuilder { } // Extension: Add the binary operators =, +=, -=, *=, /= for vector types. -for (BuiltinCandidateTypeSet::iterator - Vec1 = CandidateTypes[0].vector_begin(), - Vec1End = CandidateTypes[0].vector_end(); - Vec1 != Vec1End; ++Vec1) { - for (BuiltinCandidateTypeSet::iterator -Vec2 = CandidateTypes[1].vector_begin(), - Vec2End = CandidateTypes[1].vector_end(); - Vec2 != Vec2End; ++Vec2) { +for (QualType Vec1Ty : CandidateTypes[0].vector_types()) + for (QualType Vec2Ty : CandidateTypes[0].vector_types()) { QualType ParamTypes[2]; -ParamTypes[1] = *Vec2; +ParamTypes[1] = Vec2Ty; // Add this built-in operator as a candidate (VQ is empty). -ParamTypes[0] = S.Context.getLValueReferenceType(*Vec1); +ParamTypes[0] = S.Context.getLValueReferenceType(Vec1Ty); S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, /*IsAssignmentOperator=*/isEqualOp); // Add this built-in operator as a candidate (VQ is 'volatile'). if (VisibleTypeConversionsQuals.hasVolatile()) { - ParamTypes[0] = S.Context.getVolatileType(*Vec1); + ParamTypes[0] = S.Context.getVolatileType(Vec1Ty); ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]); S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, /*IsAssignmentOperator=*/isEq
[clang] 4affc44 - [Matrix] Implement * binary operator for MatrixType.
Author: Florian Hahn Date: 2020-06-07T11:11:27+01:00 New Revision: 4affc444b499ba2a12fee7f9ef0bb6ef33789c12 URL: https://github.com/llvm/llvm-project/commit/4affc444b499ba2a12fee7f9ef0bb6ef33789c12 DIFF: https://github.com/llvm/llvm-project/commit/4affc444b499ba2a12fee7f9ef0bb6ef33789c12.diff LOG: [Matrix] Implement * binary operator for MatrixType. This patch implements the * binary operator for values of MatrixType. It adds support for matrix * matrix, scalar * matrix and matrix * scalar. For the matrix, matrix case, the number of columns of the first operand must match the number of rows of the second. For the scalar,matrix variants, the element type of the matrix must match the scalar type. Reviewers: rjmccall, anemet, Bigcheese, rsmith, martong Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D76794 Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGExprScalar.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaOverload.cpp clang/test/CodeGen/matrix-type-operators.c clang/test/CodeGenCXX/matrix-type-operators.cpp clang/test/Sema/matrix-type-operators.c clang/test/SemaCXX/matrix-type-operators.cpp llvm/include/llvm/IR/MatrixBuilder.h Removed: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index cef25fc927aa..8f914ec451f6 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11218,6 +11218,8 @@ class Sema final { QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign); + QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign); bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); bool isLaxVectorConversion(QualType srcType, QualType destType); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index b169462f535a..cabfe0cca281 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -741,6 +741,22 @@ class ScalarExprEmitter } } +if (Ops.Ty->isConstantMatrixType()) { + llvm::MatrixBuilder MB(Builder); + // We need to check the types of the operands of the operator to get the + // correct matrix dimensions. + auto *BO = cast(Ops.E); + auto *LHSMatTy = dyn_cast( + BO->getLHS()->getType().getCanonicalType()); + auto *RHSMatTy = dyn_cast( + BO->getRHS()->getType().getCanonicalType()); + if (LHSMatTy && RHSMatTy) +return MB.CreateMatrixMultiply(Ops.LHS, Ops.RHS, LHSMatTy->getNumRows(), + LHSMatTy->getNumColumns(), + RHSMatTy->getNumColumns()); + return MB.CreateScalarMultiply(Ops.LHS, Ops.RHS); +} + if (Ops.Ty->isUnsignedIntegerType() && CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow) && !CanElideOverflowCheck(CGF.getContext(), Ops)) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d7a39cf6a6b5..45c1acecbe94 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10058,6 +10058,9 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS, return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, /*AllowBothBool*/getLangOpts().AltiVec, /*AllowBoolConversions*/false); + if (!IsDiv && (LHS.get()->getType()->isConstantMatrixType() || + RHS.get()->getType()->isConstantMatrixType())) +return CheckMatrixMultiplyOperands(LHS, RHS, Loc, IsCompAssign); QualType compType = UsualArithmeticConversions( LHS, RHS, Loc, IsCompAssign ? ACK_CompAssign : ACK_Arithmetic); @@ -12120,6 +12123,37 @@ QualType Sema::CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, return InvalidOperands(Loc, LHS, RHS); } +QualType Sema::CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, + bool IsCompAssign) { + if (!IsCompAssign) { +LHS = DefaultFunctionArrayLvalueConversion(LHS.get()); +if (LHS.isInvalid()) + return QualType(); + } + RHS = DefaultFunctionArrayLvalueConversion(RHS.get()); + if (RHS.isInvalid()) +return QualType(); + + auto *LHSMatType = LHS.get()->getType()->getAs(); + auto *RHSMatType = RHS.get()->getType()->getAs(); + assert((LHSMatType || RHSMatType) && "At least one operand must be a matrix"); + + if (LHSMatType && RHSMatType) { +if (LHSMatType->getNumColumns() != RHSMatType->getNumRows()) + return InvalidOperands(Loc, L
[clang] 3323a62 - [Matrix] Add __builtin_matrix_transpose to Clang.
Author: Florian Hahn Date: 2020-06-09T10:14:37+01:00 New Revision: 3323a628ec821b8b75d3b60bf1510931f97d3883 URL: https://github.com/llvm/llvm-project/commit/3323a628ec821b8b75d3b60bf1510931f97d3883 DIFF: https://github.com/llvm/llvm-project/commit/3323a628ec821b8b75d3b60bf1510931f97d3883.diff LOG: [Matrix] Add __builtin_matrix_transpose to Clang. This patch add __builtin_matrix_transpose to Clang, as described in clang/docs/MatrixTypes.rst. Reviewers: rjmccall, jfb, rsmith, Bigcheese Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D72778 Added: clang/test/CodeGen/matrix-type-builtins.c clang/test/CodeGenCXX/matrix-type-builtins.cpp clang/test/CodeGenObjC/matrix-type-builtins.m clang/test/Sema/matrix-type-builtins.c clang/test/SemaCXX/matrix-type-builtins.cpp clang/test/SemaObjC/matrix-type-builtins.m Modified: clang/include/clang/Basic/Builtins.def clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaChecking.cpp Removed: diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def index 4c43d63ffec4..4deca85bb867 100644 --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -577,6 +577,8 @@ BUILTIN(__builtin_alloca, "v*z" , "Fn") BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn") BUILTIN(__builtin_call_with_static_chain, "v.", "nt") +BUILTIN(__builtin_matrix_transpose, "v.", "nFt") + // "Overloaded" Atomic operator builtins. These are overloaded to support data // types of i8, i16, i32, i64, and i128. The front-end sees calls to the // non-suffixed version of these (which has a bogus type) and transforms them to diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index cce6dcc54c2f..84bcf66a148e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10779,6 +10779,9 @@ def warn_import_on_definition : Warning< "import %select{module|name}0 cannot be applied to a function with a definition">, InGroup; +def err_builtin_matrix_arg: Error< + "%select{first|second}0 argument must be a matrix">; + def err_preserve_field_info_not_field : Error< "__builtin_preserve_field_info argument %0 not a field access">; def err_preserve_field_info_not_const: Error< diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 8df78a5a7aca..33be6c68b11a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -12120,6 +12120,11 @@ class Sema final { int ArgNum, unsigned ExpectedFieldNum, bool AllowName); bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); + + // Matrix builtin handling. + ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, +ExprResult CallResult); + public: enum FormatStringType { FST_Scanf, diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index c580720379b5..bfc78ce94892 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -44,6 +44,7 @@ #include "llvm/IR/IntrinsicsWebAssembly.h" #include "llvm/IR/IntrinsicsX86.h" #include "llvm/IR/MDBuilder.h" +#include "llvm/IR/MatrixBuilder.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/TargetParser.h" @@ -2375,6 +2376,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType(; } + case Builtin::BI__builtin_matrix_transpose: { +const auto *MatrixTy = E->getArg(0)->getType()->getAs(); +Value *MatValue = EmitScalarExpr(E->getArg(0)); +MatrixBuilder MB(Builder); +Value *Result = MB.CreateMatrixTranspose(MatValue, MatrixTy->getNumRows(), + MatrixTy->getNumColumns()); +return RValue::get(Result); + } + case Builtin::BIfinite: case Builtin::BI__finite: case Builtin::BIfinitef: diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 86b18e26eb8d..0e451d6e5867 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1896,7 +1896,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, return ExprError(); break; case Builtin::BI__builtin_frame_address: - case Builtin::BI__builtin_return_address: + case Builtin::BI__builtin_return_address: { if (SemaBuiltinConstantArgRange(TheCall, 0, 0, 0x)) return ExprError(); @@ -1913,6 +1913,10 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsign
[clang] 934bcaf - [Matrix] Add __builtin_matrix_column_load to Clang.
Author: Florian Hahn Date: 2020-06-18T10:47:55+01:00 New Revision: 934bcaf10b57fc199d9b15722ea50f65a791ca4e URL: https://github.com/llvm/llvm-project/commit/934bcaf10b57fc199d9b15722ea50f65a791ca4e DIFF: https://github.com/llvm/llvm-project/commit/934bcaf10b57fc199d9b15722ea50f65a791ca4e.diff LOG: [Matrix] Add __builtin_matrix_column_load to Clang. This patch add __builtin_matrix_column_major_load to Clang, as described in clang/docs/MatrixTypes.rst. In the initial version, the stride is not optional yet. Reviewers: rjmccall, rsmith, jfb, Bigcheese Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D72781 Added: clang/test/SemaCXX/matrix-type-builtins-disabled.cpp Modified: clang/include/clang/AST/Type.h clang/include/clang/Basic/Builtins.def clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExpr.cpp clang/test/CodeGen/matrix-type-builtins.c clang/test/CodeGenCXX/matrix-type-builtins.cpp clang/test/CodeGenObjC/matrix-type-builtins.m clang/test/Sema/matrix-type-builtins.c clang/test/SemaCXX/matrix-type-builtins.cpp Removed: diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 7ff87c983037..d32e657843da 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3476,6 +3476,11 @@ class ConstantMatrixType final : public MatrixType { NumElements <= ConstantMatrixTypeBitfields::MaxElementsPerDimension; } + /// Returns the maximum number of elements per dimension. + static unsigned getMaxElementsPerDimension() { +return ConstantMatrixTypeBitfields::MaxElementsPerDimension; + } + void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, getElementType(), getNumRows(), getNumColumns(), getTypeClass()); diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def index 4deca85bb867..61a195bf5bf8 100644 --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -578,6 +578,7 @@ BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn") BUILTIN(__builtin_call_with_static_chain, "v.", "nt") BUILTIN(__builtin_matrix_transpose, "v.", "nFt") +BUILTIN(__builtin_matrix_column_major_load, "v.", "nFt") // "Overloaded" Atomic operator builtins. These are overloaded to support data // types of i8, i16, i32, i64, and i128. The front-end sees calls to the diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 52fc40771228..fb45ad8d44d9 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10786,6 +10786,18 @@ def warn_import_on_definition : Warning< def err_builtin_matrix_arg: Error< "%select{first|second}0 argument must be a matrix">; +def err_builtin_matrix_scalar_unsigned_arg: Error< + "%0 argument must be a constant unsigned integer expression">; + +def err_builtin_matrix_pointer_arg: Error< + "%select{first|second}0 argument must be a pointer to a valid matrix element type">; + +def err_builtin_matrix_stride_too_small: Error< + "stride must be greater or equal to the number of rows">; + +def err_builtin_matrix_invalid_dimension: Error< + "%0 dimension is outside the allowed range [1, %1]">; + def err_preserve_field_info_not_field : Error< "__builtin_preserve_field_info argument %0 not a field access">; def err_preserve_field_info_not_const: Error< diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 8f619b80a3e7..4f8289d70747 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -4702,6 +4702,10 @@ class Sema final { bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, UnresolvedSetImpl &NonTemplateOverloads); + /// Try to convert an expression \p E to type \p Ty. Returns the result of the + /// conversion. + ExprResult tryConvertExprToType(Expr *E, QualType Ty); + /// Conditionally issue a diagnostic based on the current /// evaluation context. /// @@ -12123,6 +12127,8 @@ class Sema final { // Matrix builtin handling. ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, ExprResult CallResult); + ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, + ExprResult CallResult); public: enum FormatStringType { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 05de88c392aa..8f8481a71ffb 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2387,6 +2387,25 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
[clang] b5e082e - [Matrix] Add __builtin_matrix_column_store to Clang.
Author: Florian Hahn Date: 2020-06-18T11:39:02+01:00 New Revision: b5e082e7289197bf82c9a28c6336b51d7999b419 URL: https://github.com/llvm/llvm-project/commit/b5e082e7289197bf82c9a28c6336b51d7999b419 DIFF: https://github.com/llvm/llvm-project/commit/b5e082e7289197bf82c9a28c6336b51d7999b419.diff LOG: [Matrix] Add __builtin_matrix_column_store to Clang. This patch add __builtin_matrix_column_major_store to Clang, as described in clang/docs/MatrixTypes.rst. In the initial version, the stride is not optional yet. Reviewers: rjmccall, jfb, rsmith, Bigcheese Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D72782 Added: Modified: clang/include/clang/Basic/Builtins.def clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaChecking.cpp clang/test/CodeGen/matrix-type-builtins.c clang/test/CodeGenCXX/matrix-type-builtins.cpp clang/test/CodeGenObjC/matrix-type-builtins.m clang/test/Sema/matrix-type-builtins.c clang/test/SemaCXX/matrix-type-builtins.cpp clang/test/SemaObjC/matrix-type-builtins.m Removed: diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def index 61a195bf5bf8..ac9af6028867 100644 --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -579,6 +579,7 @@ BUILTIN(__builtin_call_with_static_chain, "v.", "nt") BUILTIN(__builtin_matrix_transpose, "v.", "nFt") BUILTIN(__builtin_matrix_column_major_load, "v.", "nFt") +BUILTIN(__builtin_matrix_column_major_store, "v.", "nFt") // "Overloaded" Atomic operator builtins. These are overloaded to support data // types of i8, i16, i32, i64, and i128. The front-end sees calls to the diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index fb45ad8d44d9..a7b8a992f745 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10783,14 +10783,19 @@ def warn_import_on_definition : Warning< "import %select{module|name}0 cannot be applied to a function with a definition">, InGroup; -def err_builtin_matrix_arg: Error< - "%select{first|second}0 argument must be a matrix">; +def err_builtin_matrix_arg: Error<"first argument must be a matrix">; def err_builtin_matrix_scalar_unsigned_arg: Error< "%0 argument must be a constant unsigned integer expression">; def err_builtin_matrix_pointer_arg: Error< - "%select{first|second}0 argument must be a pointer to a valid matrix element type">; + "%0 argument must be a pointer to a valid matrix element type">; + +def err_builtin_matrix_pointer_arg_mismatch: Error< + "the pointee of the second argument must match the element type of the first argument (%0 != %1)">; + +def err_builtin_matrix_store_to_const: Error< + "cannot store matrix to read-only pointer">; def err_builtin_matrix_stride_too_small: Error< "stride must be greater or equal to the number of rows">; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 4f8289d70747..85c5ab476b5f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -12129,6 +12129,8 @@ class Sema final { ExprResult CallResult); ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, ExprResult CallResult); + ExprResult SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, + ExprResult CallResult); public: enum FormatStringType { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 7a138c54fb36..2339446609f6 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2406,6 +2406,25 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(Result); } + case Builtin::BI__builtin_matrix_column_major_store: { +MatrixBuilder MB(Builder); +Value *Matrix = EmitScalarExpr(E->getArg(0)); +Address Dst = EmitPointerWithAlignment(E->getArg(1)); +Value *Stride = EmitScalarExpr(E->getArg(2)); + +const auto *MatrixTy = E->getArg(0)->getType()->getAs(); +auto *PtrTy = E->getArg(1)->getType()->getAs(); +assert(PtrTy && "arg1 must be of pointer type"); +bool IsVolatile = PtrTy->getPointeeType().isVolatileQualified(); + +EmitNonNullArgCheck(RValue::get(Dst.getPointer()), E->getArg(1)->getType(), +E->getArg(1)->getExprLoc(), FD, 0); +Value *Result = MB.CreateColumnMajorStore( +Matrix, Dst.getPointer(), Align(Dst.getAlignment().getQuantity()), +Stride, IsVolatile, MatrixTy->getNumRows(), MatrixTy->getNumColumns()); +return RValue::get(R
[clang] c872e80 - [Matrix] Only pass vector arg as overloaded type in MatrixBuilder.
Author: Florian Hahn Date: 2020-07-15T10:42:24+01:00 New Revision: c872e809d1ac4aa405ae510e271f93d7662e26dd URL: https://github.com/llvm/llvm-project/commit/c872e809d1ac4aa405ae510e271f93d7662e26dd DIFF: https://github.com/llvm/llvm-project/commit/c872e809d1ac4aa405ae510e271f93d7662e26dd.diff LOG: [Matrix] Only pass vector arg as overloaded type in MatrixBuilder. In 2b3c505, the pointer arguments for the matrix load and store intrinsics was changed to always be the element type of the vector argument. This patch updates the MatrixBuilder to not add the pointer type to the overloaded types and adjusts the clang/mlir tests. This should fix a few build failures on GreenDragon, including http://green.lab.llvm.org/green/job/test-suite-verify-machineinstrs-x86_64-O0-g/7891/ Added: Modified: clang/test/CodeGen/matrix-type-builtins.c clang/test/CodeGenCXX/matrix-type-builtins.cpp clang/test/CodeGenObjC/matrix-type-builtins.m llvm/include/llvm/IR/MatrixBuilder.h mlir/test/Target/llvmir-intrinsics.mlir Removed: diff --git a/clang/test/CodeGen/matrix-type-builtins.c b/clang/test/CodeGen/matrix-type-builtins.c index 58fde6f01cc3..f7e9587def60 100644 --- a/clang/test/CodeGen/matrix-type-builtins.c +++ b/clang/test/CodeGen/matrix-type-builtins.c @@ -1,5 +1,9 @@ // RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s +// Also check we do not crash when running some middle-end passes. Most +// importantly this includes the IR verifier, to ensure we emit valid IR. +// RUN: %clang_cc1 -fenable-matrix -emit-llvm -triple x86_64-apple-darwin %s -o %t + // Tests for the matrix type builtins. typedef double dx5x5_t __attribute__((matrix_type(5, 5))); @@ -100,7 +104,7 @@ void transpose_global() { void column_major_load_with_const_stride_double(double *Ptr) { // CHECK-LABEL: define void @column_major_load_with_const_stride_double(double* %Ptr) // CHECK: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8 - // CHECK-NEXT:call <25 x double> @llvm.matrix.column.major.load.v25f64.p0f64(double* align 8 [[PTR]], i64 5, i1 false, i32 5, i32 5) + // CHECK-NEXT:call <25 x double> @llvm.matrix.column.major.load.v25f64(double* align 8 [[PTR]], i64 5, i1 false, i32 5, i32 5) dx5x5_t m_a1 = __builtin_matrix_column_major_load(Ptr, 5, 5, 5); } @@ -108,7 +112,7 @@ void column_major_load_with_const_stride_double(double *Ptr) { void column_major_load_with_const_stride2_double(double *Ptr) { // CHECK-LABEL: define void @column_major_load_with_const_stride2_double(double* %Ptr) // CHECK: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8 - // CHECK-NEXT:call <25 x double> @llvm.matrix.column.major.load.v25f64.p0f64(double* align 8 [[PTR]], i64 15, i1 false, i32 5, i32 5) + // CHECK-NEXT:call <25 x double> @llvm.matrix.column.major.load.v25f64(double* align 8 [[PTR]], i64 15, i1 false, i32 5, i32 5) dx5x5_t m_a2 = __builtin_matrix_column_major_load(Ptr, 5, 5, 2 * 3 + 9); } @@ -117,7 +121,7 @@ void column_major_load_with_variable_stride_ull_float(float *Ptr, unsigned long // CHECK-LABEL: define void @column_major_load_with_variable_stride_ull_float(float* %Ptr, i64 %S) // CHECK: [[S:%.*]] = load i64, i64* %S.addr, align 8 // CHECK-NEXT:[[PTR:%.*]] = load float*, float** %Ptr.addr, align 8 - // CHECK-NEXT:call <6 x float> @llvm.matrix.column.major.load.v6f32.p0f32(float* align 4 [[PTR]], i64 [[S]], i1 false, i32 2, i32 3) + // CHECK-NEXT:call <6 x float> @llvm.matrix.column.major.load.v6f32(float* align 4 [[PTR]], i64 [[S]], i1 false, i32 2, i32 3) fx2x3_t m_b = __builtin_matrix_column_major_load(Ptr, 2, 3, S); } @@ -128,7 +132,7 @@ void column_major_load_with_stride_math_int(int *Ptr, int S) { // CHECK-NEXT:[[STRIDE:%.*]] = add nsw i32 [[S]], 32 // CHECK-NEXT:[[STRIDE_EXT:%.*]] = sext i32 [[STRIDE]] to i64 // CHECK-NEXT:[[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8 - // CHECK-NEXT:call <80 x i32> @llvm.matrix.column.major.load.v80i32.p0i32(i32* align 4 [[PTR]], i64 [[STRIDE_EXT]], i1 false, i32 4, i32 20) + // CHECK-NEXT:call <80 x i32> @llvm.matrix.column.major.load.v80i32(i32* align 4 [[PTR]], i64 [[STRIDE_EXT]], i1 false, i32 4, i32 20) ix4x20_t m_c = __builtin_matrix_column_major_load(Ptr, 4, 20, S + 32); } @@ -140,7 +144,7 @@ void column_major_load_with_stride_math_s_int(int *Ptr, short S) { // CHECK-NEXT:[[STRIDE:%.*]] = add nsw i32 [[S_EXT]], 32 // CHECK-NEXT:[[STRIDE_EXT:%.*]] = sext i32 [[STRIDE]] to i64 // CHECK-NEXT:[[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8 - // CHECK-NEXT:%matrix = call <80 x i32> @llvm.matrix.column.major.load.v80i32.p0i32(i32* align 4 [[PTR]], i64 [[STRIDE_EXT]], i1 false, i32 4, i32 20) + // CHECK-NEXT:%matrix = ca
[clang] eb4c758 - [Matrix] Pass darwin tripe to SeamObjc test to fix windows bot failure.
Author: Florian Hahn Date: 2020-06-18T13:35:03+01:00 New Revision: eb4c758fe4b60ae3779d3e9401d00ee1450ae41b URL: https://github.com/llvm/llvm-project/commit/eb4c758fe4b60ae3779d3e9401d00ee1450ae41b DIFF: https://github.com/llvm/llvm-project/commit/eb4c758fe4b60ae3779d3e9401d00ee1450ae41b.diff LOG: [Matrix] Pass darwin tripe to SeamObjc test to fix windows bot failure. Without the triple, the test fails on a windows bot (http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/16531/steps/stage%201%20check/logs/stdio) because of different full type widths (unsigned long long vs unsigned long) Added: Modified: clang/test/SemaObjC/matrix-type-builtins.m Removed: diff --git a/clang/test/SemaObjC/matrix-type-builtins.m b/clang/test/SemaObjC/matrix-type-builtins.m index 8187bffae525..dc18905963e4 100644 --- a/clang/test/SemaObjC/matrix-type-builtins.m +++ b/clang/test/SemaObjC/matrix-type-builtins.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fenable-matrix %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fenable-matrix %s typedef double double4x4 __attribute__((matrix_type(4, 4))); typedef unsigned u4x4 __attribute__((matrix_type(4, 4))); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7213142 - [libclang] Extend clang_Cursor_Evaluate().
Author: Christian Kandeler Date: 2020-06-24T11:58:39+01:00 New Revision: 72131423cc952ccbd6d8e021ff7c04fa22297fe3 URL: https://github.com/llvm/llvm-project/commit/72131423cc952ccbd6d8e021ff7c04fa22297fe3 DIFF: https://github.com/llvm/llvm-project/commit/72131423cc952ccbd6d8e021ff7c04fa22297fe3.diff LOG: [libclang] Extend clang_Cursor_Evaluate(). Let this function (try to) evaluate expressions, in addition to declarations and compound statements. Patch by Christian Kandeler Reviewers: nik, akyrtzi, arphaman, jkorous Reviewed By: jkorous Differential Revision: https://reviews.llvm.org/D80279 Added: Modified: clang/include/clang-c/Index.h clang/test/Index/evaluate-cursor.cpp clang/tools/libclang/CIndex.cpp Removed: diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 19471af4a675..cfb8e58bfb7e 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -5934,6 +5934,7 @@ typedef void *CXEvalResult; * If cursor is a statement declaration tries to evaluate the * statement and if its variable, tries to evaluate its initializer, * into its corresponding type. + * If it's an expression, tries to evaluate the expression. */ CINDEX_LINKAGE CXEvalResult clang_Cursor_Evaluate(CXCursor C); diff --git a/clang/test/Index/evaluate-cursor.cpp b/clang/test/Index/evaluate-cursor.cpp index af396318aab7..2bb687a1eb88 100644 --- a/clang/test/Index/evaluate-cursor.cpp +++ b/clang/test/Index/evaluate-cursor.cpp @@ -26,6 +26,9 @@ template class e { static const auto g = alignof(f); }; +constexpr static int calc_val() { return 1 + 2; } +const auto the_value = calc_val() + sizeof(char); + // RUN: c-index-test -evaluate-cursor-at=%s:4:7 \ // RUN:-evaluate-cursor-at=%s:8:7 \ // RUN:-evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s @@ -53,3 +56,12 @@ template class e { // RUN:-evaluate-cursor-at=%s:26:21 \ // RUN:-std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s // CHECK-DOES-NOT-CRASH: Not Evaluatable + +// RUN: c-index-test -evaluate-cursor-at=%s:30:1 \ +// RUN:-evaluate-cursor-at=%s:30:32 \ +// RUN:-evaluate-cursor-at=%s:30:35 \ +// RUN:-evaluate-cursor-at=%s:30:37 -std=c++11 %s | FileCheck %s -check-prefix=CHECK-EXPR +// CHECK-EXPR: unsigned, Value: 4 +// CHECK-EXPR: Value: 3 +// CHECK-EXPR: unsigned, Value: 4 +// CHECK-EXPR: unsigned, Value: 1 diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 4a65624268d8..8d33deb468e2 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -4056,10 +4056,14 @@ static const Expr *evaluateCompoundStmtExpr(const CompoundStmt *CS) { } CXEvalResult clang_Cursor_Evaluate(CXCursor C) { - if (const Expr *E = - clang_getCursorKind(C) == CXCursor_CompoundStmt - ? evaluateCompoundStmtExpr(cast(getCursorStmt(C))) - : evaluateDeclExpr(getCursorDecl(C))) + const Expr *E = nullptr; + if (clang_getCursorKind(C) == CXCursor_CompoundStmt) +E = evaluateCompoundStmtExpr(cast(getCursorStmt(C))); + else if (clang_isDeclaration(C.kind)) +E = evaluateDeclExpr(getCursorDecl(C)); + else if (clang_isExpression(C.kind)) +E = getCursorExpr(C); + if (E) return const_cast( reinterpret_cast(evaluateExpr(const_cast(E), C))); return nullptr; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 22f02db - [Matrix] Group matrix diagnostics together (NFC).
Author: Florian Hahn Date: 2020-06-25T11:47:33+01:00 New Revision: 22f02db625dd3ffd7d041edb6ef5af371f4fa474 URL: https://github.com/llvm/llvm-project/commit/22f02db625dd3ffd7d041edb6ef5af371f4fa474 DIFF: https://github.com/llvm/llvm-project/commit/22f02db625dd3ffd7d041edb6ef5af371f4fa474.diff LOG: [Matrix] Group matrix diagnostics together (NFC). Added: Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td Removed: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index ec31178389f9..beccdf9a3210 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10789,35 +10789,28 @@ def err_matrix_separate_incomplete_index: Error< "matrix row and column subscripts cannot be separated by any expression">; def err_matrix_subscript_comma: Error< "comma expressions are not allowed as indices in matrix subscript expressions">; - -def warn_mismatched_import : Warning< - "import %select{module|name}0 (%1) does not match the import %select{module|name}0 (%2) of the " - "previous declaration">, - InGroup; -def warn_import_on_definition : Warning< - "import %select{module|name}0 cannot be applied to a function with a definition">, - InGroup; - def err_builtin_matrix_arg: Error<"first argument must be a matrix">; - def err_builtin_matrix_scalar_unsigned_arg: Error< "%0 argument must be a constant unsigned integer expression">; - def err_builtin_matrix_pointer_arg: Error< "%0 argument must be a pointer to a valid matrix element type">; - def err_builtin_matrix_pointer_arg_mismatch: Error< "the pointee of the second argument must match the element type of the first argument (%0 != %1)">; - def err_builtin_matrix_store_to_const: Error< "cannot store matrix to read-only pointer">; - def err_builtin_matrix_stride_too_small: Error< "stride must be greater or equal to the number of rows">; - def err_builtin_matrix_invalid_dimension: Error< "%0 dimension is outside the allowed range [1, %1]">; +def warn_mismatched_import : Warning< + "import %select{module|name}0 (%1) does not match the import %select{module|name}0 (%2) of the " + "previous declaration">, + InGroup; +def warn_import_on_definition : Warning< + "import %select{module|name}0 cannot be applied to a function with a definition">, + InGroup; + def err_preserve_field_info_not_field : Error< "__builtin_preserve_field_info argument %0 not a field access">; def err_preserve_field_info_not_const: Error< ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 043b608 - [Matrix] Use 1st/2nd instead of first/second in matrix diags.
Author: Florian Hahn Date: 2020-06-25T11:55:03+01:00 New Revision: 043b608399559969f563eaa52e11a7ffe37137d9 URL: https://github.com/llvm/llvm-project/commit/043b608399559969f563eaa52e11a7ffe37137d9 DIFF: https://github.com/llvm/llvm-project/commit/043b608399559969f563eaa52e11a7ffe37137d9.diff LOG: [Matrix] Use 1st/2nd instead of first/second in matrix diags. This was suggested in D72782 and brings the diagnostics more in line with how argument references are handled elsewhere. Reviewers: rjmccall, jfb, Bigcheese Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D82473 Added: Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaChecking.cpp clang/test/Sema/matrix-type-builtins.c clang/test/SemaCXX/matrix-type-builtins.cpp clang/test/SemaObjC/matrix-type-builtins.m Removed: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index beccdf9a3210..9067c45adc77 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10789,13 +10789,13 @@ def err_matrix_separate_incomplete_index: Error< "matrix row and column subscripts cannot be separated by any expression">; def err_matrix_subscript_comma: Error< "comma expressions are not allowed as indices in matrix subscript expressions">; -def err_builtin_matrix_arg: Error<"first argument must be a matrix">; +def err_builtin_matrix_arg: Error<"1st argument must be a matrix">; def err_builtin_matrix_scalar_unsigned_arg: Error< "%0 argument must be a constant unsigned integer expression">; def err_builtin_matrix_pointer_arg: Error< - "%0 argument must be a pointer to a valid matrix element type">; + "%ordinal0 argument must be a pointer to a valid matrix element type">; def err_builtin_matrix_pointer_arg_mismatch: Error< - "the pointee of the second argument must match the element type of the first argument (%0 != %1)">; + "the pointee of the 2nd argument must match the element type of the 1st argument (%0 != %1)">; def err_builtin_matrix_store_to_const: Error< "cannot store matrix to read-only pointer">; def err_builtin_matrix_stride_too_small: Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e6a3b54c3cc1..9d0516e0232e 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -15295,7 +15295,8 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, if (checkArgCount(*this, TheCall, 4)) return ExprError(); - Expr *PtrExpr = TheCall->getArg(0); + unsigned PtrArgIdx = 0; + Expr *PtrExpr = TheCall->getArg(PtrArgIdx); Expr *RowsExpr = TheCall->getArg(1); Expr *ColumnsExpr = TheCall->getArg(2); Expr *StrideExpr = TheCall->getArg(3); @@ -15319,14 +15320,14 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, QualType ElementTy; if (!PtrTy) { Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg) -<< "first"; +<< PtrArgIdx + 1; ArgError = true; } else { ElementTy = PtrTy->getPointeeType().getUnqualifiedType(); if (!ConstantMatrixType::isValidElementType(ElementTy)) { Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg) - << "first"; + << PtrArgIdx + 1; ArgError = true; } } @@ -15402,8 +15403,9 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, if (checkArgCount(*this, TheCall, 3)) return ExprError(); + unsigned PtrArgIdx = 1; Expr *MatrixExpr = TheCall->getArg(0); - Expr *PtrExpr = TheCall->getArg(1); + Expr *PtrExpr = TheCall->getArg(PtrArgIdx); Expr *StrideExpr = TheCall->getArg(2); bool ArgError = false; @@ -15442,7 +15444,7 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, auto *PtrTy = PtrExpr->getType()->getAs(); if (!PtrTy) { Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg) -<< "second"; +<< PtrArgIdx + 1; ArgError = true; } else { QualType ElementTy = PtrTy->getPointeeType(); diff --git a/clang/test/Sema/matrix-type-builtins.c b/clang/test/Sema/matrix-type-builtins.c index d8da11aa05aa..2f7e4549e495 100644 --- a/clang/test/Sema/matrix-type-builtins.c +++ b/clang/test/Sema/matrix-type-builtins.c @@ -11,11 +11,11 @@ void transpose(sx5x10_t a, ix3x2_t b, dx3x3 c, int *d, int e) { b = __builtin_matrix_transpose(b); // expected-error@-1 {{assigning to 'ix3x2_t' (aka 'int __attribute__((matrix_type(3, 2)))') from incompatible type 'int __attribute__((matrix_type(2, 3)))'}} __builtin_matrix_transpose(d); - // expected-error@-1 {{first argument must be a matrix}} + // expected-error@-1 {{1st argument must be a matrix}} __builtin_matrix_transpose(e); - // expected-error@-1 {{f
[clang] 7363ffe - [Matrix] Add draft specification for matrix support in Clang.
Author: Florian Hahn Date: 2020-04-27T18:00:23+01:00 New Revision: 7363ffe95f0a32b5cf11affe844577aa7ba6f0f4 URL: https://github.com/llvm/llvm-project/commit/7363ffe95f0a32b5cf11affe844577aa7ba6f0f4 DIFF: https://github.com/llvm/llvm-project/commit/7363ffe95f0a32b5cf11affe844577aa7ba6f0f4.diff LOG: [Matrix] Add draft specification for matrix support in Clang. This patch documents the planned matrix support in Clang, based on the draft specification discussed on cfe-dev in the 'Matrix Support in Clang' thread. Latest draft spec sent to cfe-dev: http://lists.llvm.org/pipermail/cfe-dev/2020-February/064742.html Discussion thread January: http://lists.llvm.org/pipermail/cfe-dev/2020-January/064206.html Discussion thread March: http://lists.llvm.org/pipermail/cfe-dev/2020-March/064834.html Reviewers: rsmith, anemet, Bigcheese, dexonsmith, rjmccall Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D76612 Added: clang/docs/MatrixTypes.rst Modified: clang/docs/LanguageExtensions.rst Removed: diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index f1b7c79db6d6..4e82a6e5 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -13,6 +13,7 @@ Clang Language Extensions BlockLanguageSpec Block-ABI-Apple AutomaticReferenceCounting + MatrixTypes Introduction @@ -492,6 +493,24 @@ See also :ref:`langext-__builtin_shufflevector`, :ref:`langext-__builtin_convert 'select', they operate somewhat diff erently. OpenCL selects based on signedness of the condition operands, but GCC vectors use normal bool conversions (that is, != 0). +Matrix Types + + +Clang provides an extension for matrix types, which is currently being +implemented. See :ref:`the draft specification ` for more details. + +For example, the code below uses the matrix types extension to multiply two 4x4 +float matrices and add the result to a third 4x4 matrix. + +.. code-block:: c++ + + typedef float m4x4_t __attribute__((matrix_type(4, 4))); + + m4x4_t f(m4x4_t a, m4x4_t b, m4x4_t c) { +return a + b * c; + } + + Half-Precision Floating Point = diff --git a/clang/docs/MatrixTypes.rst b/clang/docs/MatrixTypes.rst new file mode 100644 index ..54099e5aae93 --- /dev/null +++ b/clang/docs/MatrixTypes.rst @@ -0,0 +1,285 @@ +== +Matrix Types +== + +.. contents:: + :local: + +.. _matrixtypes: + +Clang provides a C/C++ language extension that allows users to directly express +fixed-size 2-dimensional matrices as language values and perform arithmetic on +them. + +This feature is currently experimental, and both its design and its +implementation are in flux. + +Draft Specification +=== + +Matrix Type +--- + +A matrix type is a scalar type with an underlying *element type*, a constant +number of *rows*, and a constant number of *columns*. Matrix types with the same +element type, rows, and columns are the same type. A value of a matrix type +includes storage for ``rows * columns`` values of the *element type*. The +internal layout, overall size and alignment are implementation-defined. + +The maximum of the product of the number of rows and columns is +implementation-defined. If that implementation-defined limit is exceeded, the +program is ill-formed. + +Currently, the element type of a matrix is only permitted to be one of the +following types: + +* an integer type (as in C2x 6.2.5p19), but excluding enumerated types and ``_Bool`` +* the standard floating types ``float`` or ``double`` +* a half-precision floating point type, if one is supported on the target + +Other types may be supported in the future. + +Matrix Type Attribute +- + +Matrix types can be declared by adding the ``matrix_type`` attribute to the +declaration of a *typedef* (or a C++ alias declaration). The underlying type +of the *typedef* must be a valid matrix element type. The +attribute takes two arguments, both of which must be integer constant +expressions that evaluate to a value greater than zero. The first specifies the +number of rows, and the second specifies the number of columns. The underlying +type of the *typedef* becomes a matrix type with the given dimensions and an +element type of the former underlying type. + +If a declaration of a *typedef-name* has a ``matrix_type`` attribute, then all +declaration of that *typedef-name* shall have a matrix_type attribute with the +same element type, number of rows, and number of columns. + +Standard Conversions + + +The standard conversions are extended as follows. Note that these conversions +are intentionally not listed as satisfying the constraints for assignment, +which is to say, they are only permitted as explicit casts, not as implicit +co
[clang] 00a0282 - [Clang] Remove run-lines which use opt to run -ipconstprop.
Author: Florian Hahn Date: 2020-08-02T21:47:32+01:00 New Revision: 00a0282ff8f9a790e93c19ef6fa3758e209cdbe6 URL: https://github.com/llvm/llvm-project/commit/00a0282ff8f9a790e93c19ef6fa3758e209cdbe6 DIFF: https://github.com/llvm/llvm-project/commit/00a0282ff8f9a790e93c19ef6fa3758e209cdbe6.diff LOG: [Clang] Remove run-lines which use opt to run -ipconstprop. ipconstprop is going to get removed and checking opt with specific passes makes the tests more fragile. The tests retain the important checks that !callback metadata is created correctly. Added: Modified: clang/test/CodeGen/callback_annotated.c clang/test/CodeGen/callback_openmp.c clang/test/CodeGen/callback_pthread_create.c Removed: diff --git a/clang/test/CodeGen/callback_annotated.c b/clang/test/CodeGen/callback_annotated.c index c5b431d5ef84..83a79c3491da 100644 --- a/clang/test/CodeGen/callback_annotated.c +++ b/clang/test/CodeGen/callback_annotated.c @@ -1,6 +1,4 @@ -// RUN: %clang_cc1 -triple i386-unknown-unknown -fopenmp -O1 -fno-experimental-new-pass-manager %s -emit-llvm -o - | FileCheck %s --check-prefix=RUN1 -// RUN: %clang_cc1 -triple i386-unknown-unknown -fopenmp -O1 -fno-experimental-new-pass-manager %s -emit-llvm -o - | FileCheck %s --check-prefix=RUN2 -// RUN: %clang_cc1 -triple i386-unknown-unknown -fopenmp -O1 -fno-experimental-new-pass-manager %s -emit-llvm -o - | opt -ipconstprop -S | FileCheck --check-prefix=IPCP %s +// RUN: %clang_cc1 -triple i386-unknown-unknown -fopenmp -fno-experimental-new-pass-manager %s -emit-llvm -o - -disable-llvm-optzns | FileCheck %s --check-prefix=RUN1 // RUN1-DAG: @broker0({{[^#]*#[0-9]+}} !callback ![[cid0:[0-9]+]] __attribute__((callback(1, 2))) void *broker0(void *(*callee)(void *), void *payload) { @@ -29,22 +27,10 @@ __attribute__((callback(4, -1, a, __))) void *broker4(int a, int, int, int (*cal __attribute__((callback(4, d, 5, 2))) void *broker5(int, int, int, int (*callee)(int, int, int), int d); static void *VoidPtr2VoidPtr(void *payload) { - // RUN2: ret i8* %payload - // IPCP: ret i8* null return payload; } static int ThreeInt2Int(int a, int b, int c) { - // RUN2: define internal i32 @ThreeInt2Int(i32 %a, i32 %b, i32 %c) - // RUN2: %mul = mul nsw i32 %b, %a - // RUN2: %add = add nsw i32 %mul, %c - // RUN2: ret i32 %add - - // IPCP: define internal i32 @ThreeInt2Int(i32 %a, i32 %b, i32 %c) - // IPCP: %mul = mul nsw i32 4, %a - // IPCP: %add = add nsw i32 %mul, %c - // IPCP: ret i32 %add - return a * b + c; } diff --git a/clang/test/CodeGen/callback_openmp.c b/clang/test/CodeGen/callback_openmp.c index 2fc9dcd391f6..90e63fdb2e58 100644 --- a/clang/test/CodeGen/callback_openmp.c +++ b/clang/test/CodeGen/callback_openmp.c @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -triple i386-unknown-unknown -fopenmp -O1 %s -emit-llvm -o - | FileCheck %s -// RUN: %clang_cc1 -triple i386-unknown-unknown -fopenmp -O1 %s -emit-llvm -o - | opt -ipconstprop -S | FileCheck --check-prefix=IPCP %s +// RUN: %clang_cc1 -triple i386-unknown-unknown -fopenmp %s -emit-llvm -o - -disable-llvm-optzns | FileCheck %s // CHECK: declare !callback ![[cid:[0-9]+]] void @__kmpc_fork_call // CHECK: declare !callback ![[cid]] void @__kmpc_fork_teams @@ -15,14 +14,11 @@ void foo(int q) { #pragma omp parallel firstprivate(q, p) work1(p, q); -// IPCP: call void @work1(i32 2, i32 %{{[._a-zA-Z0-9]*}}) #pragma omp parallel for firstprivate(p, q) for (int i = 0; i < q; i++) work2(i, p); -// IPCP: call void @work2(i32 %{{[._a-zA-Z0-9]*}}, i32 2) #pragma omp target teams firstprivate(p) work12(p, p); -// IPCP: call void @work12(i32 2, i32 2) } diff --git a/clang/test/CodeGen/callback_pthread_create.c b/clang/test/CodeGen/callback_pthread_create.c index 785440030b32..d1b01b91eac3 100644 --- a/clang/test/CodeGen/callback_pthread_create.c +++ b/clang/test/CodeGen/callback_pthread_create.c @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -O1 %s -S -emit-llvm -o - | FileCheck %s -// RUN: %clang_cc1 -O1 %s -S -emit-llvm -o - | opt -ipconstprop -S | FileCheck --check-prefix=IPCP %s +// RUN: %clang_cc1 %s -S -emit-llvm -o - -disable-llvm-optzns | FileCheck %s // CHECK: declare !callback ![[cid:[0-9]+]] {{.*}}i32 @pthread_create // CHECK: ![[cid]] = !{![[cidb:[0-9]+]]} @@ -21,14 +20,10 @@ int pthread_create(pthread_t *, const pthread_attr_t *, const int GlobalVar = 0; static void *callee0(void *payload) { -// IPCP: define internal i8* @callee0 -// IPCP:ret i8* null return payload; } static void *callee1(void *payload) { -// IPCP: define internal i8* @callee1 -// IPCP:ret i8* bitcast (i32* @GlobalVar to i8*) return payload; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ffcaed3 - [Matrix] Check non-dependent elt type before creating DepSizedMatrix.
Author: Florian Hahn Date: 2020-05-12T16:46:37+01:00 New Revision: ffcaed32ef1cf5226cc376b6c911183db690402f URL: https://github.com/llvm/llvm-project/commit/ffcaed32ef1cf5226cc376b6c911183db690402f DIFF: https://github.com/llvm/llvm-project/commit/ffcaed32ef1cf5226cc376b6c911183db690402f.diff LOG: [Matrix] Check non-dependent elt type before creating DepSizedMatrix. We should check non-dependent element types before creating a DependentSizedMatrixType. Otherwise we do not generate an error message for dependent-sized matrix types with invalid non-dependent element types, if the template is never instantiated. See the make5 struct in the tests. It also moves the SEMA template tests to clang/test/SemaTemplate/matrix-type.cpp and introduces a few more test cases. Added: clang/test/SemaTemplate/matrix-type.cpp Modified: clang/lib/Sema/SemaType.cpp clang/test/SemaCXX/matrix-type.cpp Removed: diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index df8ad7ad78b9..1822951266f5 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2574,11 +2574,6 @@ QualType Sema::BuildMatrixType(QualType ElementTy, Expr *NumRows, Expr *NumCols, assert(Context.getLangOpts().MatrixTypes && "Should never build a matrix type when it is disabled"); - if (NumRows->isTypeDependent() || NumCols->isTypeDependent() || - NumRows->isValueDependent() || NumCols->isValueDependent()) -return Context.getDependentSizedMatrixType(ElementTy, NumRows, NumCols, - AttrLoc); - // Check element type, if it is not dependent. if (!ElementTy->isDependentType() && !MatrixType::isValidElementType(ElementTy)) { @@ -2586,6 +2581,11 @@ QualType Sema::BuildMatrixType(QualType ElementTy, Expr *NumRows, Expr *NumCols, return QualType(); } + if (NumRows->isTypeDependent() || NumCols->isTypeDependent() || + NumRows->isValueDependent() || NumCols->isValueDependent()) +return Context.getDependentSizedMatrixType(ElementTy, NumRows, NumCols, + AttrLoc); + // Both row and column values can only be 20 bit wide currently. llvm::APSInt ValueRows(32), ValueColumns(32); diff --git a/clang/test/SemaCXX/matrix-type.cpp b/clang/test/SemaCXX/matrix-type.cpp index 76f288d83e6e..af31e267fdca 100644 --- a/clang/test/SemaCXX/matrix-type.cpp +++ b/clang/test/SemaCXX/matrix-type.cpp @@ -29,101 +29,3 @@ void matrix_unsupported_element_type() { using matrix3_t = bool __attribute__((matrix_type(1, 1))); // expected-error{{invalid matrix element type 'bool'}} using matrix4_t = TestEnum __attribute__((matrix_type(1, 1))); // expected-error{{invalid matrix element type 'TestEnum'}} } - -template // expected-note{{declared here}} -void matrix_template_1() { - using matrix1_t = float __attribute__((matrix_type(T, T))); // expected-error{{'T' does not refer to a value}} -} - -template // expected-note{{declared here}} -void matrix_template_2() { - using matrix1_t = float __attribute__((matrix_type(C, C))); // expected-error{{'C' does not refer to a value}} -} - -template -void matrix_template_3() { - using matrix1_t = float __attribute__((matrix_type(Rows, Cols))); // expected-error{{zero matrix size}} -} - -void instantiate_template_3() { - matrix_template_3<1, 10>(); - matrix_template_3<0, 10>(); // expected-note{{in instantiation of function template specialization 'matrix_template_3<0, 10>' requested here}} -} - -template -void matrix_template_4() { - using matrix1_t = float __attribute__((matrix_type(Rows, Cols))); // expected-error{{matrix row size too large}} -} - -void instantiate_template_4() { - matrix_template_4<2, 10>(); - matrix_template_4<-3, 10>(); // expected-note{{in instantiation of function template specialization 'matrix_template_4<-3, 10>' requested here}} -} - -template -using matrix = T __attribute__((matrix_type(R, C))); - -template -void use_matrix(matrix &m) {} -// expected-note@-1 {{candidate function [with T = float, R = 10]}} - -template -void use_matrix(matrix &m) {} -// expected-note@-1 {{candidate function [with T = float, C = 10]}} - -void test_ambigous_deduction1() { - matrix m; - use_matrix(m); - // expected-error@-1 {{call to 'use_matrix' is ambiguous}} -} - -template -void type_conflict(matrix &m, T x) {} -// expected-note@-1 {{candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'char *')}} - -void test_type_conflict(char *p) { - matrix m; - type_conflict(m, p); - // expected-error@-1 {{no matching function for call to 'type_conflict'}} -} - -template -matrix use_matrix_2(matrix &m) {} -// expected-note@-1 {{candidate function template not viable: requires single argument 'm', but 2 arguments were provided}} -// expected-note@-2 {{candidate function template not viabl
[lld] [polly] [openmp] [llvm] [flang] [clang] [mlir] [compiler-rt] [lldb] [VPlan] Compute scalable VF in preheader for induction increment. (PR #74762)
@@ -340,8 +340,13 @@ Value *VPInstruction::generateInstruction(VPTransformState &State, auto *Phi = State.get(getOperand(0), 0); // The loop step is equal to the vectorization factor (num of SIMD // elements) times the unroll factor (num of SIMD instructions). - Value *Step = - createStepForVF(Builder, Phi->getType(), State.VF, State.UF); + Value *Step; + { +BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this); +IRBuilder<>::InsertPointGuard Guard(Builder); +Builder.SetInsertPoint(VectorPH->getTerminator()); fhahn wrote: Adjusted in the latest version, thanks! https://github.com/llvm/llvm-project/pull/74762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[flang] [lldb] [mlir] [polly] [openmp] [compiler-rt] [lld] [clang] [llvm] [VPlan] Compute scalable VF in preheader for induction increment. (PR #74762)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/74762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [flang] [lld] [polly] [lldb] [openmp] [clang] [compiler-rt] [mlir] [VPlan] Initial modeling of VF * UF as VPValue. (PR #74761)
https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/74761 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [openmp] [lldb] [polly] [mlir] [lld] [llvm] [clang] [flang] [VPlan] Initial modeling of VF * UF as VPValue. (PR #74761)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/74761 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)
fhahn wrote: It looks like this breaks building at least `MultiSource` from https://github.com/llvm/llvm-test-suite/. The first failure I see is when building `llvm-test-suite/MultiSource/Applications/ClamAV/zlib_zutil.c` ``` In file included from /llvm-test-suite/MultiSource/Applications/ClamAV/zlib_zutil.c:10: In file included from test-suites/llvm-test-suite/MultiSource/Applications/ClamAV/zlib/gzguts.h:21: ../usr/include/stdio.h:220:7: error: expected identifier or '(' 220 | FILE*fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen)); | ^ llvm-test-suite/MultiSource/Applications/ClamAV/zlib/zutil.h:140:33: note: expanded from macro 'fdopen' 140 | #define fdopen(fd,mode) NULL /* No fdopen() */ | ^ llvm-project/builds/release-with-assertions/ccache-stage1/lib/clang/18/include/__stddef_null.h:26:16: note: expanded from macro 'NULL' 26 | #define NULL ((void*)0) |^ ``` I think it also breaks building PovRay from SPEC2017. https://github.com/llvm/llvm-project/pull/74676 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)
fhahn wrote: Please also see the failures on GreenDragon: https://green.lab.llvm.org/green/job/lnt-ctmark-aarch64-Os/15893/console https://github.com/llvm/llvm-project/pull/74676 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Fix] Disable fdefine-target-os-macros for now (PR #74886)
https://github.com/fhahn approved this pull request. LGTM, thanks! For reference, this is breaking llvm-test-suite builds, e.g. see https://green.lab.llvm.org/green/job/lnt-ctmark-aarch64-Os/15893/console https://github.com/llvm/llvm-project/pull/74886 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[lldb] [clang] [openmp] [polly] [flang] [mlir] [compiler-rt] [llvm] [lld] [VPlan] Compute scalable VF in preheader for induction increment. (PR #74762)
@@ -340,8 +340,14 @@ Value *VPInstruction::generateInstruction(VPTransformState &State, auto *Phi = State.get(getOperand(0), 0); // The loop step is equal to the vectorization factor (num of SIMD // elements) times the unroll factor (num of SIMD instructions). - Value *Step = - createStepForVF(Builder, Phi->getType(), State.VF, State.UF); + Value *Step; + { +BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this); +IRBuilder<> PHBuilder(VectorPH->getTerminator()); +// Step is loop-invariant, calls to vscale will be placed in the +// preheader. +Step = createStepForVF(PHBuilder, Phi->getType(), State.VF, State.UF); + } fhahn wrote: The cow has been remove in https://github.com/llvm/llvm-project/commit/a5891fa4d2b76cf9dec96da9ded59fc4937d3342 https://github.com/llvm/llvm-project/pull/74762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[lldb] [clang] [openmp] [polly] [flang] [mlir] [compiler-rt] [llvm] [lld] [VPlan] Compute scalable VF in preheader for induction increment. (PR #74762)
https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/74762 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)
https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/73515 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)
@@ -346,7 +346,9 @@ void RuntimePointerChecking::tryToCreateDiffCheck( auto *SinkStartAR = cast(SinkStartInt); const Loop *StartARLoop = SrcStartAR->getLoop(); if (StartARLoop == SinkStartAR->getLoop() && -StartARLoop == InnerLoop->getParentLoop()) { +StartARLoop == InnerLoop->getParentLoop() && +SrcStartAR->getStepRecurrence(*SE) != fhahn wrote: Yeah the UI does unfortunately sometimes hide some comments :( https://github.com/llvm/llvm-project/pull/73515 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)
https://github.com/fhahn approved this pull request. LGTM, thanks for the update! https://github.com/llvm/llvm-project/pull/73515 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[lld] [libunwind] [libcxxabi] [libcxx] [compiler-rt] [llvm] [flang] [mlir] [clang-tools-extra] [lldb] [clang] [Passes] Disable code sinking in InstCombine early on. (PR #72567)
https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/72567 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [LoopVectorize] Enable hoisting of runtime checks by default (PR #71538)
https://github.com/fhahn approved this pull request. LGTM with the earlier adjustments, thanks! https://github.com/llvm/llvm-project/pull/71538 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang] [flang] [lldb] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)
fhahn wrote: Looks like this is causing #75938. Please take a look https://github.com/llvm/llvm-project/pull/71072 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [lldb] [clang-tools-extra] [flang] [clang] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)
fhahn wrote: @markoshorro Great thanks. Please revert the patch if you won't be able to fix this today. https://github.com/llvm/llvm-project/pull/71072 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 419a4e4 - Revert "[clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (#71677)"
Author: Florian Hahn Date: 2023-11-23T20:18:55Z New Revision: 419a4e41fc36a91999da6cbe06d430cac07224f1 URL: https://github.com/llvm/llvm-project/commit/419a4e41fc36a91999da6cbe06d430cac07224f1 DIFF: https://github.com/llvm/llvm-project/commit/419a4e41fc36a91999da6cbe06d430cac07224f1.diff LOG: Revert "[clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (#71677)" This reverts commit fe5c360a9aae61db37886c0c795c409b5129905f. The commit causes the tests below to fail on many buildbots, e.g. https://lab.llvm.org/buildbot/#/builders/245/builds/17047 Clang :: CodeGen/aapcs-align.cpp Clang :: CodeGen/aapcs64-align.cpp Added: Modified: clang/lib/CodeGen/CGDecl.cpp clang/test/CodeGenCXX/auto-var-init.cpp clang/test/CodeGenOpenCL/amdgpu-printf.cl clang/test/OpenMP/bug54082.c Removed: diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index a5da0aa2965a000..e5795d811c76de7 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1244,24 +1244,29 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, // If the initializer is small, use a handful of stores. if (shouldSplitConstantStore(CGM, ConstantSize)) { if (auto *STy = dyn_cast(Ty)) { - const llvm::StructLayout *Layout = - CGM.getDataLayout().getStructLayout(STy); - for (unsigned i = 0; i != constant->getNumOperands(); i++) { -CharUnits CurOff = CharUnits::fromQuantity(Layout->getElementOffset(i)); -Address EltPtr = Builder.CreateConstInBoundsByteGEP( -Loc.withElementType(CGM.Int8Ty), CurOff); -emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, - constant->getAggregateElement(i), IsAutoInit); + // FIXME: handle the case when STy != Loc.getElementType(). + if (STy == Loc.getElementType()) { +for (unsigned i = 0; i != constant->getNumOperands(); i++) { + Address EltPtr = Builder.CreateStructGEP(Loc, i); + emitStoresForConstant( + CGM, D, EltPtr, isVolatile, Builder, + cast(Builder.CreateExtractValue(constant, i)), + IsAutoInit); +} +return; } - return; } else if (auto *ATy = dyn_cast(Ty)) { - for (unsigned i = 0; i != ATy->getNumElements(); i++) { -Address EltPtr = Builder.CreateConstGEP( -Loc.withElementType(ATy->getElementType()), i); -emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, - constant->getAggregateElement(i), IsAutoInit); + // FIXME: handle the case when ATy != Loc.getElementType(). + if (ATy == Loc.getElementType()) { +for (unsigned i = 0; i != ATy->getNumElements(); i++) { + Address EltPtr = Builder.CreateConstArrayGEP(Loc, i); + emitStoresForConstant( + CGM, D, EltPtr, isVolatile, Builder, + cast(Builder.CreateExtractValue(constant, i)), + IsAutoInit); +} +return; } - return; } } diff --git a/clang/test/CodeGenCXX/auto-var-init.cpp b/clang/test/CodeGenCXX/auto-var-init.cpp index e5a9d015f22f276..6cb18528ebadcdf 100644 --- a/clang/test/CodeGenCXX/auto-var-init.cpp +++ b/clang/test/CodeGenCXX/auto-var-init.cpp @@ -89,14 +89,22 @@ struct padded { char c; int i; }; // PATTERN-O1-NOT: @__const.test_paddednullinit_custom.custom struct paddednullinit { char c = 0; int i = 0; }; // PATTERN-O0: @__const.test_paddedpacked_uninit.uninit = private unnamed_addr constant %struct.paddedpacked <{ i8 [[I8]], i32 [[I32]] }>, align 1 +// PATTERN: @__const.test_paddedpacked_custom.custom = private unnamed_addr constant %struct.paddedpacked <{ i8 42, i32 13371337 }>, align 1 +// ZERO: @__const.test_paddedpacked_custom.custom = private unnamed_addr constant %struct.paddedpacked <{ i8 42, i32 13371337 }>, align 1 struct paddedpacked { char c; int i; } __attribute__((packed)); // PATTERN-O0: @__const.test_paddedpackedarray_uninit.uninit = private unnamed_addr constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] [%struct.paddedpacked <{ i8 [[I8]], i32 [[I32]] }>, %struct.paddedpacked <{ i8 [[I8]], i32 [[I32]] }>] }, align 1 +// PATTERN: @__const.test_paddedpackedarray_custom.custom = private unnamed_addr constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] [%struct.paddedpacked <{ i8 42, i32 13371337 }>, %struct.paddedpacked <{ i8 43, i32 13371338 }>] }, align 1 +// ZERO: @__const.test_paddedpackedarray_custom.custom = private unnamed_addr constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] [%struct.paddedpacked <{ i8 42, i32 13371337 }>, %struct.paddedpacked <{ i8 43, i32 13371338 }>] }, align 1 struct paddedpackedarray { struct paddedpacked p[2]; }; // PATTERN-O0: @__const.test_unpackedinpacked_uninit.uninit
[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)
fhahn wrote: Reverted the change for now, as many build bots have been red due to the test failures https://github.com/llvm/llvm-project/pull/71677 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)
fhahn wrote: @serge-sans-paille those test failures were also highlighted by the precommit checks, would be good to check those before landing https://github.com/llvm/llvm-project/pull/71677 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)
https://github.com/fhahn approved this pull request. LGTM, looks like a great first step! Will be interesting to see what kind of regressions this surfaces (if any) https://github.com/llvm/llvm-project/pull/68882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Emit distinct TBAA tags for pointers with different depths,types. (PR #76612)
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/76612 This patch extends Clang's TBAA generation code to emit distinct tags for incompatible pointer types. Pointers with different element types are incompatible if the pointee types are also incompatible (modulo sugar/modifiers). Express this in TBAA by generating different tags for pointers based on the pointer depth and pointee type. To get the TBAA tag for the pointee type it uses getTypeInfoHelper on the pointee type. (Moved from https://reviews.llvm.org/D122573) >From 18f45a0b989d90a0f649dcc7b00f05be58fbe0c9 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 30 Dec 2023 10:39:58 + Subject: [PATCH] [TBAA] Emit distinct TBAA tags for pointers with different depths,types. This patch extends Clang's TBAA generation code to emit distinct tags for incompatible pointer types. Pointers with different element types are incompatible if the pointee types are also incompatible (modulo sugar/modifiers). Express this in TBAA by generating different tags for pointers based on the pointer depth and pointee type. To get the TBAA tag for the pointee type it uses getTypeInfoHelper on the pointee type. (Moved from https://reviews.llvm.org/D122573) --- clang/lib/CodeGen/CodeGenTBAA.cpp | 29 ++-- clang/test/CodeGen/tbaa-pointers.c | 72 +- 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index dc288bc3f6157a..b96f9d28c45530 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -184,10 +184,31 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) { return getChar(); // Handle pointers and references. - // TODO: Implement C++'s type "similarity" and consider dis-"similar" - // pointers distinct. - if (Ty->isPointerType() || Ty->isReferenceType()) -return createScalarTypeNode("any pointer", getChar(), Size); + if (Ty->isPointerType() || Ty->isReferenceType()) { +llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), Size); +// Compute the depth of the pointer and generate a tag of the form "p +// ". +unsigned PtrDepth = 0; +do { + PtrDepth++; + Ty = Ty->getPointeeType().getTypePtr(); +} while (Ty->isPointerType() || Ty->isReferenceType()); +// TODO: Implement C++'s type "similarity" and consider dis-"similar" +// pointers distinct for non-builtin types. +if (isa(Ty)) { + llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty); + StringRef Name = + cast( + ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0)) + ->getString(); + SmallString<256> OutName("p"); + OutName += std::to_string(PtrDepth); + OutName += " "; + OutName += Name; + return createScalarTypeNode(OutName, AnyPtr, Size); +} +return AnyPtr; + } // Accesses to arrays are accesses to objects of their element types. if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType()) diff --git a/clang/test/CodeGen/tbaa-pointers.c b/clang/test/CodeGen/tbaa-pointers.c index b9ebe879820012..a3a7aa0d66473e 100644 --- a/clang/test/CodeGen/tbaa-pointers.c +++ b/clang/test/CodeGen/tbaa-pointers.c @@ -4,9 +4,9 @@ void p2unsigned(unsigned **ptr) { // CHECK-LABEL: define void @p2unsigned(ptr noundef %ptr) // CHECK-NEXT: entry: // CHECK-NEXT: %ptr.addr = alloca ptr, align 8 - // CHECK-NEXT: store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0:!.+]] - // CHECK-NEXT: [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] - // CHECK-NEXT: store ptr null, ptr [[BASE]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0:!.+]] + // CHECK-NEXT: [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0]] + // CHECK-NEXT: store ptr null, ptr [[BASE]], align 8, !tbaa [[P1INT_0:!.+]] // CHECK-NEXT: ret void // *ptr = 0; @@ -16,9 +16,9 @@ void p2unsigned_volatile(unsigned *volatile *ptr) { // CHECK-LABEL: define void @p2unsigned_volatile(ptr noundef %ptr) // CHECK-NEXT: entry: // CHECK-NEXT: %ptr.addr = alloca ptr, align 8 - // CHECK-NEXT: store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] - // CHECK-NEXT: [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] - // CHECK-NEXT: store volatile ptr null, ptr [[BASE]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0]] + // CHECK-NEXT: [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0]] + // CHECK-NEXT: store volatile ptr null, ptr [[BASE]], align 8, !tbaa [[P1INT_0]] // CHECK-NEXT: ret void // *ptr = 0; @@ -28,10 +28,10 @@ void p3int(int ***ptr) { // CHECK-LABEL: define void @p3int(ptr noundef %ptr) // CHECK-NEXT: entry: // CHECK-NEXT: %ptr.a
[clang] [TBAA] Emit distinct TBAA tags for pointers with different depths,types. (PR #76612)
fhahn wrote: Move this over from Phabricator, see https://reviews.llvm.org/D122573 http://108.170.204.19/D122573 for context. Type sanitizer patches have been moved to GH as well: #76259, #76260, #76261 https://discourse.llvm.org/t/reviving-typesanitizer-a-sanitizer-to-catch-type-based-aliasing-violations/66092/ https://github.com/llvm/llvm-project/pull/76612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)
fhahn wrote: Thanks for working on this! I think it would be good to split this up into multiple distinct parts for the different improvements. I put up a patch to support distinct metadata for distinct pointers a while ago, which I just moved to GH: #76261. The discussion on Phabricator has some interesting points and one of the concerns was that it is very difficult already to detect type violations in source code, which makes adopting more powerful TBAA features quite difficult. There are some tooling improvements we can make here, including a sanitizer for types, which would be good to get rolling again, see https://discourse.llvm.org/t/reviving-typesanitizer-a-sanitizer-to-catch-type-based-aliasing-violations/66092 TBAA union support and potential issues have been discussed in detail a number of years ago on the old mailing list (llvm-dev), did you have a look at those threads? https://github.com/llvm/llvm-project/pull/75177 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)
fhahn wrote: @aeubanks thanks for the revert! https://github.com/llvm/llvm-project/pull/75841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [Matrix] Convert column-vector ops feeding dot product to row-vectors. (PR #72647)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/72647 >From 3dfe86782806f048b130d46afa6293712919f672 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 14 Apr 2023 14:33:57 +0100 Subject: [PATCH] [Matrix] Convert column-vector ops feeding dot product to row-vectors. Generalize the logic used to convert column-vector ops to row-vectors to support converting chains of operations. A potential next step is to further generalize this to convert column-vector ops to row-vector ops in general, not just for operands of dot products. Dot-product handling would then be driven by the general conversion, rather than the other way around. --- .../Scalar/LowerMatrixIntrinsics.cpp | 51 ++- .../LowerMatrixIntrinsics/dot-product-int.ll | 47 - 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp index 72b9db1e73d73d..c6bb43d3a78cf3 100644 --- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp +++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp @@ -1332,8 +1332,8 @@ class LowerMatrixIntrinsics { if (!IsIntVec && !FMF.allowReassoc()) return; -auto CanBeFlattened = [this](Value *Op) { - if (match(Op, m_BinOp()) && ShapeMap.find(Op) != ShapeMap.end()) +auto CanBeFlattened = [](Value *Op) { + if (match(Op, m_BinOp())) return true; return match( Op, m_OneUse(m_CombineOr( @@ -1346,6 +1346,9 @@ class LowerMatrixIntrinsics { // the returned cost is < 0, the argument is cheaper to use in the // dot-product lowering. auto GetCostForArg = [this, &CanBeFlattened](Value *Op, unsigned N) { + if (ShapeMap.find(Op) == ShapeMap.end()) +return InstructionCost::getInvalid(); + if (!isa(Op)) return InstructionCost(0); @@ -1356,7 +1359,7 @@ class LowerMatrixIntrinsics { InstructionCost EmbedCost(0); // Roughly estimate the cost for embedding the columns into a vector. for (unsigned I = 1; I < N; ++I) - EmbedCost -= + EmbedCost += TTI.getShuffleCost(TTI::SK_Splice, FixedVectorType::get(EltTy, 1), std::nullopt, TTI::TCK_RecipThroughput); return EmbedCost; @@ -1378,7 +1381,7 @@ class LowerMatrixIntrinsics { // vector. InstructionCost EmbedCost(0); for (unsigned I = 1; I < N; ++I) - EmbedCost += + EmbedCost -= TTI.getShuffleCost(TTI::SK_Splice, FixedVectorType::get(EltTy, 1), std::nullopt, TTI::TCK_RecipThroughput); return EmbedCost; @@ -1391,7 +1394,26 @@ class LowerMatrixIntrinsics { return TTI.getMemoryOpCost(Instruction::Load, VecTy, Align(1), 0) - N * TTI.getMemoryOpCost(Instruction::Load, EltTy, Align(1), 0); }; -auto LHSCost = GetCostForArg(LHS, LShape.NumColumns); + +SmallPtrSet Seen; +SmallVector WorkList; +SmallVector ToFlatten; +WorkList.push_back(LHS); +InstructionCost LHSCost(0); +while (!WorkList.empty()) { + Value *Op = WorkList.pop_back_val(); + if (!Seen.insert(Op).second) +continue; + + InstructionCost OpCost = GetCostForArg(Op, LShape.NumColumns); + if (OpCost + LHSCost >= LHSCost) +continue; + + LHSCost += OpCost; + ToFlatten.push_back(Op); + if (auto *I = dyn_cast(Op)) +WorkList.append(I->op_begin(), I->op_end()); +} // We compare the costs of a vector.reduce.add to sequential add. int AddOpCode = IsIntVec ? Instruction::Add : Instruction::FAdd; @@ -1412,16 +1434,16 @@ class LowerMatrixIntrinsics { FusedInsts.insert(MatMul); IRBuilder<> Builder(MatMul); auto FlattenArg = [&Builder, &FusedInsts, &CanBeFlattened, - this](Value *Op) -> Value * { + this](Value *Op) { // Matmul must be the only user of loads because we don't use LowerLoad // for row vectors (LowerLoad results in scalar loads and shufflevectors // instead of single vector load). if (!CanBeFlattened(Op)) -return Op; +return; if (match(Op, m_BinOp()) && ShapeMap.find(Op) != ShapeMap.end()) { ShapeMap[Op] = ShapeMap[Op].t(); -return Op; +return; } FusedInsts.insert(cast(Op)); @@ -1432,16 +1454,19 @@ class LowerMatrixIntrinsics { auto *NewLoad = Builder.CreateLoad(Op->getType(), Arg); Op->replaceAllUsesWith(NewLoad); cast(Op)->eraseFromParent(); -return NewLoad; +return; } else if (match(Op, m_Intrinsic( m_Value(Arg { ToRemove.push_back(cast(Op)); -return Arg; +Op->replaceAllUsesWith(Arg); +return; } - - return Op; }; -LHS = FlattenArg(LHS);
[clang-tools-extra] [llvm] [Matrix] Convert column-vector ops feeding dot product to row-vectors. (PR #72647)
fhahn wrote: ping :) https://github.com/llvm/llvm-project/pull/72647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [llvm] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/76090 >From 7c31c8bc2acf60bd50cb6d63944ee8d4946b9638 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 4 May 2023 21:33:24 +0100 Subject: [PATCH] [VPlan] Replace VPRecieOrVPValue with VP2VP recipe simplification. Move simplification of VPBlendRecipes from early VPlan construction to VPlan-to-VPlan based recipe simplification. This simplifies initial construction. Note that some in-loop reduction tests are failing at the moment, due to the reduction predicate being created after the reduction recipe. I will provide a patch for that soon. --- .../Transforms/Vectorize/LoopVectorize.cpp| 99 +++ .../Transforms/Vectorize/VPRecipeBuilder.h| 23 ++--- .../Transforms/Vectorize/VPlanTransforms.cpp | 34 ++- .../Transforms/Vectorize/VPlanTransforms.h| 1 - 4 files changed, 74 insertions(+), 83 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index f82e161fb846d1..609a927d23754b 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8256,31 +8256,10 @@ VPWidenIntOrFpInductionRecipe *VPRecipeBuilder::tryToOptimizeInductionTruncate( return nullptr; } -VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode *Phi, -ArrayRef Operands, -VPlanPtr &Plan) { - // If all incoming values are equal, the incoming VPValue can be used directly - // instead of creating a new VPBlendRecipe. - if (llvm::all_equal(Operands)) -return Operands[0]; - +VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi, + ArrayRef Operands, + VPlanPtr &Plan) { unsigned NumIncoming = Phi->getNumIncomingValues(); - // For in-loop reductions, we do not need to create an additional select. - VPValue *InLoopVal = nullptr; - for (unsigned In = 0; In < NumIncoming; In++) { -PHINode *PhiOp = -dyn_cast_or_null(Operands[In]->getUnderlyingValue()); -if (PhiOp && CM.isInLoopReduction(PhiOp)) { - assert(!InLoopVal && "Found more than one in-loop reduction!"); - InLoopVal = Operands[In]; -} - } - - assert((!InLoopVal || NumIncoming == 2) && - "Found an in-loop reduction for PHI with unexpected number of " - "incoming values"); - if (InLoopVal) -return Operands[Operands[0] == InLoopVal ? 1 : 0]; // We know that all PHIs in non-header blocks are converted into selects, so // we don't have to worry about the insertion order and we can just use the @@ -8292,13 +8271,13 @@ VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode *Phi, for (unsigned In = 0; In < NumIncoming; In++) { VPValue *EdgeMask = createEdgeMask(Phi->getIncomingBlock(In), Phi->getParent(), *Plan); -assert((EdgeMask || NumIncoming == 1) && +assert((EdgeMask || NumIncoming == 1 || Operands[In] == Operands[0]) && "Multiple predecessors with one having a full mask"); OperandsWithMask.push_back(Operands[In]); if (EdgeMask) OperandsWithMask.push_back(EdgeMask); } - return toVPRecipeResult(new VPBlendRecipe(Phi, OperandsWithMask)); + return new VPBlendRecipe(Phi, OperandsWithMask); } VPWidenCallRecipe *VPRecipeBuilder::tryToWidenCall(CallInst *CI, @@ -8464,9 +8443,8 @@ void VPRecipeBuilder::fixHeaderPhis() { } } -VPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(Instruction *I, - VFRange &Range, - VPlan &Plan) { +VPRecipeBase *VPRecipeBuilder::handleReplication(Instruction *I, VFRange &Range, + VPlan &Plan) { bool IsUniform = LoopVectorizationPlanner::getDecisionAndClampRange( [&](ElementCount VF) { return CM.isUniformAfterVectorization(I, VF); }, Range); @@ -8518,14 +8496,12 @@ VPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(Instruction *I, auto *Recipe = new VPReplicateRecipe(I, Plan.mapToVPValues(I->operands()), IsUniform, BlockInMask); - return toVPRecipeResult(Recipe); + return Recipe; } -VPRecipeOrVPValueTy -VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr, -ArrayRef Operands, -VFRange &Range, VPBasicBlock *VPBB, -VPlanPtr &Plan) { +VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe( +Instruction *Instr, ArrayRef Operands, VFRange &Range, +VPBasicBlock *VPBB, VPlanPtr &Plan) { // First, check for specific widening recipes that deal with inductions, Phi // nodes, calls and memory operations. VPRecipeBase *Recipe; @@ -8538,7 +8514,7 @@ VPReci
[lld] [libcxx] [openmp] [llvm] [clang] [lto] Add minimum macos sdk requirement to test (PR #77695)
fhahn wrote: Hmmm, did you try this with a newer SDK to confirm it works as expected or is possible that it now just doesn't run? Do you know what SDK version the failing system has? The option handling is done by `libLTO` built from source, so I'd be surprised if that doesn't get passed through https://github.com/llvm/llvm-project/pull/77695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/77023 >From ddecbda9f079584a55feed322d8d20b766349ab9 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 4 Jan 2024 22:07:31 + Subject: [PATCH 1/2] [VPlan] Introduce VPSingleDefRecipe. This patch introduces a new common base class for recipes defining a single result VPValue. This has been discussed/mentioned at various previous reviews as potential follow-up and helps to replace various getVPSingleValue calls. --- .../Transforms/Vectorize/LoopVectorize.cpp| 28 ++- llvm/lib/Transforms/Vectorize/VPlan.h | 177 -- .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 4 +- .../Transforms/Vectorize/VPlanTransforms.cpp | 36 ++-- 4 files changed, 152 insertions(+), 93 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 10c068e3b5895c..6cb77bfa0beffd 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8937,12 +8937,12 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( "AnyOf reductions are not allowed for in-loop reductions"); // Collect the chain of "link" recipes for the reduction starting at PhiR. -SetVector Worklist; +SetVector Worklist; Worklist.insert(PhiR); for (unsigned I = 0; I != Worklist.size(); ++I) { - VPRecipeBase *Cur = Worklist[I]; - for (VPUser *U : Cur->getVPSingleValue()->users()) { -auto *UserRecipe = dyn_cast(U); + VPSingleDefRecipe *Cur = Worklist[I]; + for (VPUser *U : Cur->users()) { +auto *UserRecipe = dyn_cast(U); if (!UserRecipe) continue; assert(UserRecipe->getNumDefinedValues() == 1 && @@ -8956,10 +8956,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( // (PreviousLink) to tell which of the two operands of a Link will remain // scalar and which will be reduced. For minmax by select(cmp), Link will be // the select instructions. -VPRecipeBase *PreviousLink = PhiR; // Aka Worklist[0]. -for (VPRecipeBase *CurrentLink : Worklist.getArrayRef().drop_front()) { - VPValue *PreviousLinkV = PreviousLink->getVPSingleValue(); - +VPSingleDefRecipe *PreviousLink = PhiR; // Aka Worklist[0]. +for (VPSingleDefRecipe *CurrentLink : Worklist.getArrayRef().drop_front()) { Instruction *CurrentLinkI = CurrentLink->getUnderlyingInstr(); // Index of the first operand which holds a non-mask vector operand. @@ -8974,7 +8972,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( "Expected instruction to be a call to the llvm.fmuladd intrinsic"); assert(((MinVF.isScalar() && isa(CurrentLink)) || isa(CurrentLink)) && - CurrentLink->getOperand(2) == PreviousLinkV && + CurrentLink->getOperand(2) == PreviousLink && "expected a call where the previous link is the added operand"); // If the instruction is a call to the llvm.fmuladd intrinsic then we @@ -9005,15 +9003,15 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( // Note that for non-commutable operands (cmp-selects), the semantics of // the cmp-select are captured in the recurrence kind. unsigned VecOpId = -CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLinkV +CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLink ? IndexOfFirstOperand + 1 : IndexOfFirstOperand; VecOp = CurrentLink->getOperand(VecOpId); -assert(VecOp != PreviousLinkV && +assert(VecOp != PreviousLink && CurrentLink->getOperand(CurrentLink->getNumOperands() - 1 - (VecOpId - IndexOfFirstOperand)) == - PreviousLinkV && - "PreviousLinkV must be the operand other than VecOp"); + PreviousLink && + "PreviousLink must be the operand other than VecOp"); } BasicBlock *BB = CurrentLinkI->getParent(); @@ -9025,13 +9023,13 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( } VPReductionRecipe *RedRecipe = new VPReductionRecipe( - RdxDesc, CurrentLinkI, PreviousLinkV, VecOp, CondOp); + RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp); // Append the recipe to the end of the VPBasicBlock because we need to // ensure that it comes after all of it's inputs, including CondOp. // Note that this transformation may leave over dead recipes (including // CurrentLink), which will be cleaned by a later VPlan transform. LinkVPBB->appendRecipe(RedRecipe); - CurrentLink->getVPSingleValue()->replaceAllUsesWith(RedRecipe); + CurrentLink->replaceAllUsesWith(RedRecipe); PreviousLink = RedRecipe; } } diff --git a
[llvm] [clang] [clang-tools-extra] [VPlan] Introduce VPSingleDefRecipe. (PR #77023)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/77023 >From ddecbda9f079584a55feed322d8d20b766349ab9 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 4 Jan 2024 22:07:31 + Subject: [PATCH 1/3] [VPlan] Introduce VPSingleDefRecipe. This patch introduces a new common base class for recipes defining a single result VPValue. This has been discussed/mentioned at various previous reviews as potential follow-up and helps to replace various getVPSingleValue calls. --- .../Transforms/Vectorize/LoopVectorize.cpp| 28 ++- llvm/lib/Transforms/Vectorize/VPlan.h | 177 -- .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 4 +- .../Transforms/Vectorize/VPlanTransforms.cpp | 36 ++-- 4 files changed, 152 insertions(+), 93 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 10c068e3b5895c..6cb77bfa0beffd 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8937,12 +8937,12 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( "AnyOf reductions are not allowed for in-loop reductions"); // Collect the chain of "link" recipes for the reduction starting at PhiR. -SetVector Worklist; +SetVector Worklist; Worklist.insert(PhiR); for (unsigned I = 0; I != Worklist.size(); ++I) { - VPRecipeBase *Cur = Worklist[I]; - for (VPUser *U : Cur->getVPSingleValue()->users()) { -auto *UserRecipe = dyn_cast(U); + VPSingleDefRecipe *Cur = Worklist[I]; + for (VPUser *U : Cur->users()) { +auto *UserRecipe = dyn_cast(U); if (!UserRecipe) continue; assert(UserRecipe->getNumDefinedValues() == 1 && @@ -8956,10 +8956,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( // (PreviousLink) to tell which of the two operands of a Link will remain // scalar and which will be reduced. For minmax by select(cmp), Link will be // the select instructions. -VPRecipeBase *PreviousLink = PhiR; // Aka Worklist[0]. -for (VPRecipeBase *CurrentLink : Worklist.getArrayRef().drop_front()) { - VPValue *PreviousLinkV = PreviousLink->getVPSingleValue(); - +VPSingleDefRecipe *PreviousLink = PhiR; // Aka Worklist[0]. +for (VPSingleDefRecipe *CurrentLink : Worklist.getArrayRef().drop_front()) { Instruction *CurrentLinkI = CurrentLink->getUnderlyingInstr(); // Index of the first operand which holds a non-mask vector operand. @@ -8974,7 +8972,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( "Expected instruction to be a call to the llvm.fmuladd intrinsic"); assert(((MinVF.isScalar() && isa(CurrentLink)) || isa(CurrentLink)) && - CurrentLink->getOperand(2) == PreviousLinkV && + CurrentLink->getOperand(2) == PreviousLink && "expected a call where the previous link is the added operand"); // If the instruction is a call to the llvm.fmuladd intrinsic then we @@ -9005,15 +9003,15 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( // Note that for non-commutable operands (cmp-selects), the semantics of // the cmp-select are captured in the recurrence kind. unsigned VecOpId = -CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLinkV +CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLink ? IndexOfFirstOperand + 1 : IndexOfFirstOperand; VecOp = CurrentLink->getOperand(VecOpId); -assert(VecOp != PreviousLinkV && +assert(VecOp != PreviousLink && CurrentLink->getOperand(CurrentLink->getNumOperands() - 1 - (VecOpId - IndexOfFirstOperand)) == - PreviousLinkV && - "PreviousLinkV must be the operand other than VecOp"); + PreviousLink && + "PreviousLink must be the operand other than VecOp"); } BasicBlock *BB = CurrentLinkI->getParent(); @@ -9025,13 +9023,13 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( } VPReductionRecipe *RedRecipe = new VPReductionRecipe( - RdxDesc, CurrentLinkI, PreviousLinkV, VecOp, CondOp); + RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp); // Append the recipe to the end of the VPBasicBlock because we need to // ensure that it comes after all of it's inputs, including CondOp. // Note that this transformation may leave over dead recipes (including // CurrentLink), which will be cleaned by a later VPlan transform. LinkVPBB->appendRecipe(RedRecipe); - CurrentLink->getVPSingleValue()->replaceAllUsesWith(RedRecipe); + CurrentLink->replaceAllUsesWith(RedRecipe); PreviousLink = RedRecipe; } } diff --git a
[clang] ca47ab1 - [Clang] Remove unused function declaration after 77475ffd22418ca72.
Author: Florian Hahn Date: 2022-06-27T14:17:53+01:00 New Revision: ca47ab128bf33d1e2aa753da76f1224b53c37661 URL: https://github.com/llvm/llvm-project/commit/ca47ab128bf33d1e2aa753da76f1224b53c37661 DIFF: https://github.com/llvm/llvm-project/commit/ca47ab128bf33d1e2aa753da76f1224b53c37661.diff LOG: [Clang] Remove unused function declaration after 77475ffd22418ca72. Added: Modified: clang/lib/CodeGen/SanitizerMetadata.h Removed: diff --git a/clang/lib/CodeGen/SanitizerMetadata.h b/clang/lib/CodeGen/SanitizerMetadata.h index 41e1dca32aad..3ac97889d7dd 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.h +++ b/clang/lib/CodeGen/SanitizerMetadata.h @@ -47,10 +47,6 @@ class SanitizerMetadata { void disableSanitizerForGlobal(llvm::GlobalVariable *GV); void disableSanitizerForInstruction(llvm::Instruction *I); -private: - void reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc, -StringRef Name, QualType Ty, bool IsDynInit, -bool IsExcluded); llvm::MDNode *getLocationMetadata(SourceLocation Loc); }; } // end namespace CodeGen ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9eb6572 - [LV] Add back CantReorderMemOps remark.
Author: Florian Hahn Date: 2022-07-04T17:23:47+01:00 New Revision: 9eb657278611665433d30fb37979d1df48af2ac8 URL: https://github.com/llvm/llvm-project/commit/9eb657278611665433d30fb37979d1df48af2ac8 DIFF: https://github.com/llvm/llvm-project/commit/9eb657278611665433d30fb37979d1df48af2ac8.diff LOG: [LV] Add back CantReorderMemOps remark. Add back remark unintentionally dropped by 644a965c1efef68f. I will add a LV test separately, so we do not have to rely on a Clang test to catch this. Added: Modified: clang/test/Frontend/optimization-remark-options.c llvm/lib/Transforms/Vectorize/LoopVectorize.cpp Removed: diff --git a/clang/test/Frontend/optimization-remark-options.c b/clang/test/Frontend/optimization-remark-options.c index 3509a388d0f6..96e480d140be 100644 --- a/clang/test/Frontend/optimization-remark-options.c +++ b/clang/test/Frontend/optimization-remark-options.c @@ -1,5 +1,5 @@ // REQUIRES: x86-registered-target -// RUN: %clang -O1 -fvectorize -target x86_64-unknown-unknown -Rpass-analysis=loop-vectorize -emit-llvm -S %s -o - 2>&1 | FileCheck %s +// RUN: %clang -O1 -fvectorize -target x86_64-unknown-unknown -mllvm -vectorize-memory-check-threshold=8 -Rpass-analysis=loop-vectorize -emit-llvm -S %s -o - 2>&1 | FileCheck %s // CHECK: {{.*}}:10:11: remark: loop not vectorized: cannot prove it is safe to reorder floating-point operations; allow reordering by specifying '#pragma clang loop vectorize(enable)' before the loop or by providing the compiler option '-ffast-math'. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index c9e9136bbd3c..b48c3e18def5 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -10514,8 +10514,18 @@ bool LoopVectorizePass::processLoop(Loop *L) { bool ForceVectorization = Hints.getForce() == LoopVectorizeHints::FK_Enabled; if (!ForceVectorization && -!areRuntimeChecksProfitable(Checks, VF, L, *PSE.getSE())) +!areRuntimeChecksProfitable(Checks, VF, L, *PSE.getSE())) { + ORE->emit([&]() { +return OptimizationRemarkAnalysisAliasing( + DEBUG_TYPE, "CantReorderMemOps", L->getStartLoc(), + L->getHeader()) + << "loop not vectorized: cannot prove it is safe to reorder " + "memory operations"; + }); + LLVM_DEBUG(dbgs() << "LV: Too many memory checks needed.\n"); + Hints.emitRemarkWithHints(); return false; +} } // Identify the diagnostic messages that should be produced. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 171cdba - [Clang, TBAA] Use pattern for metadata reference in test.
Author: Florian Hahn Date: 2022-03-25T18:12:39Z New Revision: 171cdba8674f05bc9b97b6d194911292d4a73731 URL: https://github.com/llvm/llvm-project/commit/171cdba8674f05bc9b97b6d194911292d4a73731 DIFF: https://github.com/llvm/llvm-project/commit/171cdba8674f05bc9b97b6d194911292d4a73731.diff LOG: [Clang,TBAA] Use pattern for metadata reference in test. Update the single check line that still had a hard-coded metadata reference. This makes it more robust to slight changes in the metadata numbering. Added: Modified: clang/test/CodeGen/tbaa.cpp Removed: diff --git a/clang/test/CodeGen/tbaa.cpp b/clang/test/CodeGen/tbaa.cpp index 554daf875b5b5..02dbd87452b93 100644 --- a/clang/test/CodeGen/tbaa.cpp +++ b/clang/test/CodeGen/tbaa.cpp @@ -281,7 +281,7 @@ uint32_t g15(StructS *S, StructS3 *S3, uint64_t count) { // NEW-PATH-DAG: [[TYPE_short:!.*]] = !{[[TYPE_char]], i64 2, !"short"} // NEW-PATH-DAG: [[TYPE_int:!.*]] = !{[[TYPE_char]], i64 4, !"int"} // NEW-PATH-DAG: [[TAG_i32:!.*]] = !{[[TYPE_int]], [[TYPE_int]], i64 0, i64 4} -// NEW-PATH-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS7StructA", [[TYPE_short]], i64 0, i64 2, [[TYPE_int]], i64 4, i64 4, !12, i64 8, i64 2, [[TYPE_int]], i64 12, i64 4} +// NEW-PATH-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS7StructA", [[TYPE_short]], i64 0, i64 2, [[TYPE_int]], i64 4, i64 4, [[TYPE_short]], i64 8, i64 2, [[TYPE_int]], i64 12, i64 4} // NEW-PATH-DAG: [[TAG_A_f16]] = !{[[TYPE_A]], [[TYPE_short]], i64 0, i64 2} // NEW-PATH-DAG: [[TAG_A_f32]] = !{[[TYPE_A]], [[TYPE_int]], i64 4, i64 4} // NEW-PATH-DAG: [[TYPE_B:!.*]] = !{[[TYPE_char]], i64 24, !"_ZTS7StructB", [[TYPE_short]], i64 0, i64 2, [[TYPE_A]], i64 4, i64 16, [[TYPE_int]], i64 20, i64 4} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] bb9bdef - [Clang] Use pattern to match profile metadata in test.
Author: Florian Hahn Date: 2022-03-25T21:05:58Z New Revision: bb9bdef4df8a9db4f9ff4ed340cf59948f2145c7 URL: https://github.com/llvm/llvm-project/commit/bb9bdef4df8a9db4f9ff4ed340cf59948f2145c7 DIFF: https://github.com/llvm/llvm-project/commit/bb9bdef4df8a9db4f9ff4ed340cf59948f2145c7.diff LOG: [Clang] Use pattern to match profile metadata in test. Make the test more robust to slightly different metadata numbering by using a pattern instead of hard coding the ids. Added: Modified: clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp Removed: diff --git a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp index b20537bd784a3..eeb6a8b672965 100644 --- a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp +++ b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp @@ -9,9 +9,9 @@ extern bool c(); void ab1(int &i) { // CHECK-LABEL: define{{.*}}ab1 - // CHECK: br {{.*}} !prof !6 - // CHECK: br {{.*}} !prof !6 - // CHECK: br {{.*}} !prof !6 + // CHECK: br {{.*}} !prof [[BW_LIKELY:!.+]] + // CHECK: br {{.*}} !prof [[BW_LIKELY]] + // CHECK: br {{.*}} !prof [[BW_LIKELY]] if (__builtin_expect(a() && b() && a(), 1)) { ++i; } else { @@ -21,9 +21,9 @@ void ab1(int &i) { void al(int &i) { // CHECK-LABEL: define{{.*}}al - // CHECK: br {{.*}} !prof !6 - // CHECK: br {{.*}} !prof !6 - // CHECK: br {{.*}} !prof !6 + // CHECK: br {{.*}} !prof [[BW_LIKELY]] + // CHECK: br {{.*}} !prof [[BW_LIKELY]] + // CHECK: br {{.*}} !prof [[BW_LIKELY]] if (a() && b() && c()) [[likely]] { ++i; } else { @@ -36,7 +36,7 @@ void ab0(int &i) { // CHECK: br {{.*}}end{{$}} // CHECK: br {{.*}}end{{$}} // CHECK: br {{.*}}end{{$}} - // CHECK: br {{.*}} !prof !9 + // CHECK: br {{.*}} !prof [[BW_UNLIKELY:!.+]] if (__builtin_expect(a() && b() && c(), 0)) { ++i; } else { @@ -48,7 +48,7 @@ void au(int &i) { // CHECK-LABEL: define{{.*}}au // CHECK: br {{.*}}else{{$}} // CHECK: br {{.*}}else{{$}} - // CHECK: br {{.*}} !prof !9 + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] if (a() && b() && c()) [[unlikely]] { ++i; } else { @@ -61,7 +61,7 @@ void ob1(int &i) { // CHECK: br {{.*}}false{{$}} // CHECK: br {{.*}}rhs{{$}} // CHECK: br {{.*}}end{{$}} - // CHECK: br {{.*}} !prof !6 + // CHECK: br {{.*}} !prof [[BW_LIKELY]] if (__builtin_expect(a() || b() || a(), 1)) { i = 0; } else { @@ -73,7 +73,7 @@ void ol(int &i) { // CHECK-LABEL: define{{.*}}ol // CHECK: br {{.*}}false{{$}} // CHECK: br {{.*}}false2{{$}} - // CHECK: br {{.*}} !prof !6 + // CHECK: br {{.*}} !prof [[BW_LIKELY]] if (a() || b() || c()) [[likely]] { i = 0; } else { @@ -83,9 +83,9 @@ void ol(int &i) { void ob0(int &i) { // CHECK-LABEL: define{{.*}}ob0 - // CHECK: br {{.*}} !prof !9 - // CHECK: br {{.*}} !prof !9 - // CHECK: br {{.*}} !prof !9 + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] if (__builtin_expect(a() || b() || c(), 0)) { i = 0; } else { @@ -95,9 +95,9 @@ void ob0(int &i) { void ou(int &i) { // CHECK-LABEL: define{{.*}}ou - // CHECK: br {{.*}} !prof !9 - // CHECK: br {{.*}} !prof !9 - // CHECK: br {{.*}} !prof !9 + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] if (a() || b() || c()) [[unlikely]] { i = 0; } else { @@ -107,7 +107,7 @@ void ou(int &i) { void nb1(int &i) { // CHECK-LABEL: define{{.*}}nb1 - // CHECK: br {{.*}} !prof !6 + // CHECK: br {{.*}} !prof [[BW_LIKELY]] if (__builtin_expect(!a(), 1)) { ++i; } else { @@ -117,7 +117,7 @@ void nb1(int &i) { void nl(int &i) { // CHECK-LABEL: define{{.*}}nl - // CHECK: br {{.*}} !prof !6 + // CHECK: br {{.*}} !prof [[BW_LIKELY]] if (bool d = !a()) [[likely]] { ++i; } else { @@ -127,7 +127,7 @@ void nl(int &i) { void nb0(int &i) { // CHECK-LABEL: define{{.*}}nb0 - // CHECK: br {{.*}} !prof !9 + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] if (__builtin_expect(!a(), 0)) { ++i; } else { @@ -137,7 +137,7 @@ void nb0(int &i) { void nu(int &i) { // CHECK-LABEL: define{{.*}}nu - // CHECK: br {{.*}} !prof !9 + // CHECK: br {{.*}} !prof [[BW_UNLIKELY]] if (bool d = !a()) [[unlikely]] { ++i; } else { @@ -150,7 +150,7 @@ void tb1(int &i) { // CHECK: br {{.*}}false{{$}} // CHECK: br {{.*}}end{{$}} // CHECK: br {{.*}}end{{$}} - // CHECK: br {{.*}} !prof !6 + // CHECK: br {{.*}} !prof [[BW_LIKELY]] if (__builtin_expect(a() ? b() : c(), 1)) { ++i; } else { @@ -163,7 +163,7 @@ void tl(int &i) { // CHECK: br {{.*}}false{{$}} // CHECK: br {{.*}}end{{$}} // CHECK: br {{.*}}end{{$}} - // CHECK: br {{.*}}
[clang] 8b245ab - [Clang, TBAA] Add test cases for nested pointers and TBAA data.
Author: Florian Hahn Date: 2022-03-27T19:59:37+01:00 New Revision: 8b245ab41dfaed153e9ce768470107ec71551e1f URL: https://github.com/llvm/llvm-project/commit/8b245ab41dfaed153e9ce768470107ec71551e1f DIFF: https://github.com/llvm/llvm-project/commit/8b245ab41dfaed153e9ce768470107ec71551e1f.diff LOG: [Clang,TBAA] Add test cases for nested pointers and TBAA data. Added: clang/test/CodeGen/tbaa-pointers.c Modified: Removed: diff --git a/clang/test/CodeGen/tbaa-pointers.c b/clang/test/CodeGen/tbaa-pointers.c new file mode 100644 index 0..bde26d17e1430 --- /dev/null +++ b/clang/test/CodeGen/tbaa-pointers.c @@ -0,0 +1,103 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s + +void p2unsigned(unsigned **ptr) { + // CHECK-LABEL: define void @p2unsigned(i32** noundef %ptr) + // CHECK-NEXT: entry: + // CHECK-NEXT: %ptr.addr = alloca i32**, align 8 + // CHECK-NEXT: store i32** %ptr, i32*** %ptr.addr, align 8, !tbaa [[ANY_POINTER_0:!.+]] + // CHECK-NEXT: [[BASE:%.+]] = load i32**, i32*** %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store i32* null, i32** [[BASE]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: ret void + // + *ptr = 0; +} + +void p2unsigned_volatile(unsigned *volatile *ptr) { + // CHECK-LABEL: define void @p2unsigned_volatile(i32** noundef %ptr) + // CHECK-NEXT: entry: + // CHECK-NEXT: %ptr.addr = alloca i32**, align 8 + // CHECK-NEXT: store i32** %ptr, i32*** %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE:%.+]] = load i32**, i32*** %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store volatile i32* null, i32** [[BASE]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: ret void + // + *ptr = 0; +} + +void p3int(int ***ptr) { + // CHECK-LABEL: define void @p3int(i32*** noundef %ptr) + // CHECK-NEXT: entry: + // CHECK-NEXT: %ptr.addr = alloca i32***, align 8 + // CHECK-NEXT: store i32*** %ptr, i32 %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_0:%.+]] = load i32***, i32 %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_1:%.+]] = load i32**, i32*** [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store i32* null, i32** [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: ret void + // + **ptr = 0; +} + +void p4char(char ptr) { + // CHECK-LABEL: define void @p4char(i8 noundef %ptr) + // CHECK-NEXT: entry: + // CHECK-NEXT: %ptr.addr = alloca i8, align 8 + // CHECK-NEXT: store i8 %ptr, i8* %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_0:%.+]] = load i8, i8* %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_1:%.+]] = load i8***, i8 [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_2:%.+]] = load i8**, i8*** [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store i8* null, i8** [[BASE_2]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: ret void + // + ***ptr = 0; +} + +void p4char_const1(const char ptr) { + // CHECK-LABEL: define void @p4char_const1(i8 noundef %ptr) + // CHECK-NEXT: entry: + // CHECK-NEXT: %ptr.addr = alloca i8, align 8 + // CHECK-NEXT: store i8 %ptr, i8* %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_0:%.+]] = load i8, i8* %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_1:%.+]] = load i8***, i8 [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_2:%.+]] = load i8**, i8*** [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store i8* null, i8** [[BASE_2]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: ret void + // + ***ptr = 0; +} + +void p4char_const2(const char **const **ptr) { + // CHECK-LABEL: define void @p4char_const2(i8 noundef %ptr) + // CHECK-NEXT: entry: + // CHECK-NEXT: %ptr.addr = alloca i8, align 8 + // CHECK-NEXT: store i8 %ptr, i8* %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_0:%.+]] = load i8, i8* %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_1:%.+]] = load i8***, i8 [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: [[BASE_2:%.+]] = load i8**, i8*** [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: store i8* null, i8** [[BASE_2]], align 8, !tbaa [[ANY_POINTER_0]] + // CHECK-NEXT: ret void + // + ***ptr = 0; +} + +struct S1 { + int x; + int y; +}; + +void p2struct(struct S1 **ptr) { + // CHECK-LABEL: define void @p2struct(%struct.S1** noundef %ptr) + // CHECK-NEXT: entry: + // CHECK-NEXT: %ptr.addr = alloca %struct.S1**, align 8 + // CHECK-NEXT: store %struct.S1** %ptr, %struct.S1*** %ptr.addr, align 8, !tbaa [[ANY_P
[clang] fbe022f - [Libcalls] Add tests with maytrap & non-errno for math libcalls.
Author: Florian Hahn Date: 2022-07-29T13:45:34+01:00 New Revision: fbe022f18961bb2523072cf9d2649db81b0592c0 URL: https://github.com/llvm/llvm-project/commit/fbe022f18961bb2523072cf9d2649db81b0592c0 DIFF: https://github.com/llvm/llvm-project/commit/fbe022f18961bb2523072cf9d2649db81b0592c0.diff LOG: [Libcalls] Add tests with maytrap & non-errno for math libcalls. Added: Modified: clang/test/CodeGen/math-libcalls.c Removed: diff --git a/clang/test/CodeGen/math-libcalls.c b/clang/test/CodeGen/math-libcalls.c index bf259d7e783be..d1af31631bb22 100644 --- a/clang/test/CodeGen/math-libcalls.c +++ b/clang/test/CodeGen/math-libcalls.c @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown -Wno-implicit-function-declaration -w -S -o - -emit-llvm %s | FileCheck %s --check-prefix=NO__ERRNO // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown -Wno-implicit-function-declaration -w -S -o - -emit-llvm -fmath-errno %s | FileCheck %s --check-prefix=HAS_ERRNO +// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown -Wno-implicit-function-declaration -w -S -o - -emit-llvm -ffp-exception-behavior=maytrap %s | FileCheck %s --check-prefix=HAS_MAYTRAP // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown-gnu -Wno-implicit-function-declaration -w -S -o - -emit-llvm -fmath-errno %s | FileCheck %s --check-prefix=HAS_ERRNO_GNU // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-windows-msvc -Wno-implicit-function-declaration -w -S -o - -emit-llvm -fmath-errno %s | FileCheck %s --check-prefix=HAS_ERRNO_WIN @@ -8,66 +9,87 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) { f = fmod(f,f); f = fmodf(f,f);f = fmodl(f,f); -// NO__ERRNO: frem double -// NO__ERRNO: frem float -// NO__ERRNO: frem x86_fp80 -// HAS_ERRNO: declare double @fmod(double noundef, double noundef) [[NOT_READNONE:#[0-9]+]] -// HAS_ERRNO: declare float @fmodf(float noundef, float noundef) [[NOT_READNONE]] -// HAS_ERRNO: declare x86_fp80 @fmodl(x86_fp80 noundef, x86_fp80 noundef) [[NOT_READNONE]] + // NO__ERRNO: frem double + // NO__ERRNO: frem float + // NO__ERRNO: frem x86_fp80 + // HAS_ERRNO: declare double @fmod(double noundef, double noundef) [[NOT_READNONE:#[0-9]+]] + // HAS_ERRNO: declare float @fmodf(float noundef, float noundef) [[NOT_READNONE]] + // HAS_ERRNO: declare x86_fp80 @fmodl(x86_fp80 noundef, x86_fp80 noundef) [[NOT_READNONE]] + // HAS_MAYTRAP: declare double @llvm.experimental.constrained.frem.f64( + // HAS_MAYTRAP: declare float @llvm.experimental.constrained.frem.f32( + // HAS_MAYTRAP: declare x86_fp80 @llvm.experimental.constrained.frem.f80( atan2(f,f);atan2f(f,f) ; atan2l(f, f); -// NO__ERRNO: declare double @atan2(double noundef, double noundef) [[READNONE:#[0-9]+]] -// NO__ERRNO: declare float @atan2f(float noundef, float noundef) [[READNONE]] -// NO__ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) [[READNONE]] -// HAS_ERRNO: declare double @atan2(double noundef, double noundef) [[NOT_READNONE]] -// HAS_ERRNO: declare float @atan2f(float noundef, float noundef) [[NOT_READNONE]] -// HAS_ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) [[NOT_READNONE]] + // NO__ERRNO: declare double @atan2(double noundef, double noundef) [[READNONE:#[0-9]+]] + // NO__ERRNO: declare float @atan2f(float noundef, float noundef) [[READNONE]] + // NO__ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) [[READNONE]] + // HAS_ERRNO: declare double @atan2(double noundef, double noundef) [[NOT_READNONE]] + // HAS_ERRNO: declare float @atan2f(float noundef, float noundef) [[NOT_READNONE]] + // HAS_ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) [[NOT_READNONE]] + // HAS_MAYTRAP: declare double @atan2(double noundef, double noundef) [[READNONE:#[0-9]+]] + // HAS_MAYTRAP: declare float @atan2f(float noundef, float noundef) [[READNONE]] + // HAS_MAYTRAP: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) [[READNONE]] copysign(f,f); copysignf(f,f);copysignl(f,f); -// NO__ERRNO: declare double @llvm.copysign.f64(double, double) [[READNONE_INTRINSIC:#[0-9]+]] -// NO__ERRNO: declare float @llvm.copysign.f32(float, float) [[READNONE_INTRINSIC]] -// NO__ERRNO: declare x86_fp80 @llvm.copysign.f80(x86_fp80, x86_fp80) [[READNONE_INTRINSIC]] -// HAS_ERRNO: declare double @llvm.copysign.f64(double, double) [[READNONE_INTRINSIC:#[0-9]+]] -// HAS_ERRNO: declare float @llvm.copysign.f32(float, float) [[READNONE_INTRINSIC]] -// HAS_ERRNO: declare x86_fp80 @llvm.copysign.f80(x86_fp80, x86_fp80) [[READNONE_INTRINSIC]] + // NO__ERRNO: declare double @llvm.copysign.f64(double, double) [[READNONE_INTRINSIC:#[0-9]+]] + // NO__ERRNO: declare float @llvm.copysign.f32(float, float)
[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/84569 >From 99ca952b60344d2ff683d05d8baa423aa11da83a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 8 Mar 2024 13:36:18 -0800 Subject: [PATCH 1/2] [WebAssembly] Change the default linker for `wasm32-wasip2` This commit changes the default linker in the WebAssembly toolchain for the `wasm32-wasip2` target. This target is being added to the WebAssembly/wasi-sdk and WebAssembly/wasi-libc projects to target the Component Model by default, in contrast with the preexisting `wasm32-wasi` target (in the process of being renamed to `wasm32-wasip1`) which outputs a core WebAssembly module by default. The `wasm-component-ld` project currently lives in my GitHub account at https://github.com/alexcrichton/wasm-component-ld and isn't necessarily "official" yet, but it's expected to continue to evolve as the `wasm32-wasip2` target continues to shape up and evolve. --- clang/lib/Driver/ToolChains/WebAssembly.cpp | 6 ++ clang/lib/Driver/ToolChains/WebAssembly.h | 2 +- clang/test/Driver/wasm-toolchain.c | 8 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp index b8c2573d6265fb..a6c43c627f7206 100644 --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -221,6 +221,12 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, } } +const char *WebAssembly::getDefaultLinker() const { + if (getOS() == "wasip2") +return "wasm-component-ld"; + return "wasm-ld"; +} + bool WebAssembly::IsMathErrnoDefault() const { return false; } bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } diff --git a/clang/lib/Driver/ToolChains/WebAssembly.h b/clang/lib/Driver/ToolChains/WebAssembly.h index ae60f464c10818..76e0ca39bd748d 100644 --- a/clang/lib/Driver/ToolChains/WebAssembly.h +++ b/clang/lib/Driver/ToolChains/WebAssembly.h @@ -67,7 +67,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly final : public ToolChain { llvm::opt::ArgStringList &CmdArgs) const override; SanitizerMask getSupportedSanitizers() const override; - const char *getDefaultLinker() const override { return "wasm-ld"; } + const char *getDefaultLinker() const override; CXXStdlibType GetDefaultCXXStdlibType() const override { return ToolChain::CST_Libcxx; diff --git a/clang/test/Driver/wasm-toolchain.c b/clang/test/Driver/wasm-toolchain.c index f950283ec42aa0..59cfdfb3cb113b 100644 --- a/clang/test/Driver/wasm-toolchain.c +++ b/clang/test/Driver/wasm-toolchain.c @@ -197,3 +197,11 @@ // RUN: not %clang -### %s --target=wasm32-unknown-unknown --sysroot=%s/no-sysroot-there -fPIC -mno-mutable-globals %s 2>&1 \ // RUN: | FileCheck -check-prefix=PIC_NO_MUTABLE_GLOBALS %s // PIC_NO_MUTABLE_GLOBALS: error: invalid argument '-fPIC' not allowed with '-mno-mutable-globals' + +// Test that `wasm32-wasip2` invokes the `wasm-component-ld` linker by default +// instead of `wasm-ld`. + +// RUN: %clang -### -O2 --target=wasm32-wasip2 %s --sysroot /foo 2>&1 \ +// RUN: | FileCheck -check-prefix=LINK_WASIP2 %s +// LINK_WASIP2: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" +// LINK_WASIP2: wasm-component-ld{{.*}}" "-L/foo/lib/wasm32-wasip2" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" >From d1a1b22da3e1361a34f2d4fa8a2f9ef361f109ee Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 18 Mar 2024 12:23:23 -0700 Subject: [PATCH 2/2] Pass a path to `wasm-ld` to `wasm-component-ld` This commit adds an explicit argument that's passed to `wasm-component-ld` containing the location of `wasm-ld` itself. This enables `wasm-component-ld` to avoid hunting around looking for it and instead use the install that's paired with Clang itself. Additionally this reinterprets the `-fuse-ld=lld` argument to explicitly requesting the `wasm-ld` linker flavor, even on `wasm32-wasip2` targets. --- clang/lib/Driver/ToolChains/WebAssembly.cpp | 20 ++-- clang/test/Driver/wasm-toolchain.c | 16 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp index a6c43c627f7206..61bf9d8aae72d2 100644 --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -44,8 +44,15 @@ std::string wasm::Linker::getLinkerPath(const ArgList &Args) const { llvm::sys::fs::can_execute(UseLinker)) return std::string(UseLinker); - // Accept 'lld', and 'ld' as aliases for the default linker - if (UseLinker != "lld" && UseLinker != "ld") + // Interpret 'lld' as explicitly requesting `wasm-ld`, so look for that + // linker. Note that for `wasm32-wasip2` this overrides the default linker + // of `wasm-component-ld`. + if
[llvm] [clang-tools-extra] [flang] [clang] [Matrix] Convert column-vector ops feeding dot product to row-vectors. (PR #72647)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/72647 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [clang-tools-extra] [libc] [flang] [VPlan] Consistently use (Part, 0) for first lane scalar values (PR #80271)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/80271 >From f4dabdfaa66744ecfca4c0a57472a357db9715d9 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 31 Jan 2024 14:02:38 + Subject: [PATCH 1/3] [VPlan] Update VPInst::onlyFirstLaneUsed to check users. A VPInstruction only has its first lane used if all users use its first lane only. Use vputils::onlyFirstLaneUsed to continue checking the recipe's users to handle more cases. Besides allowing additional introduction of scalar steps when interleaving in some cases, this also enables using an Add VPInstruction to model the increment. --- llvm/lib/Transforms/Vectorize/VPlan.cpp | 4 +- llvm/lib/Transforms/Vectorize/VPlan.h | 20 +-- .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 18 ++ .../pr45679-fold-tail-by-masking.ll | 160 +- .../tail-folding-vectorization-factor-1.ll| 66 5 files changed, 129 insertions(+), 139 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index a1bd6aaf0e551..1ca2cfef447f6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -1397,9 +1397,9 @@ void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) { assignSlot(Def); } -bool vputils::onlyFirstLaneUsed(VPValue *Def) { +bool vputils::onlyFirstLaneUsed(const VPValue *Def) { return all_of(Def->users(), -[Def](VPUser *U) { return U->onlyFirstLaneUsed(Def); }); +[Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); }); } bool vputils::onlyFirstPartUsed(VPValue *Def) { diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 20792cb9ac7c1..30dc521947b3b 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1256,23 +1256,7 @@ class VPInstruction : public VPRecipeWithIRFlags { } } - /// Returns true if the recipe only uses the first lane of operand \p Op. - bool onlyFirstLaneUsed(const VPValue *Op) const override { -assert(is_contained(operands(), Op) && - "Op must be an operand of the recipe"); -if (getOperand(0) != Op) - return false; -switch (getOpcode()) { -default: - return false; -case VPInstruction::ActiveLaneMask: -case VPInstruction::CalculateTripCountMinusVF: -case VPInstruction::CanonicalIVIncrementForPart: -case VPInstruction::BranchOnCount: - return true; -}; -llvm_unreachable("switch should return"); - } + bool onlyFirstLaneUsed(const VPValue *Op) const override; /// Returns true if the recipe only uses the first part of operand \p Op. bool onlyFirstPartUsed(const VPValue *Op) const override { @@ -3385,7 +3369,7 @@ class VPlanSlp { namespace vputils { /// Returns true if only the first lane of \p Def is used. -bool onlyFirstLaneUsed(VPValue *Def); +bool onlyFirstLaneUsed(const VPValue *Def); /// Returns true if only the first part of \p Def is used. bool onlyFirstPartUsed(VPValue *Def); diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index e51184b0dd1fe..21b8d1eb77bf9 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -515,6 +515,24 @@ void VPInstruction::execute(VPTransformState &State) { State.set(this, GeneratedValue, Part); } } +bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const { + assert(is_contained(operands(), Op) && "Op must be an operand of the recipe"); + if (Instruction::isBinaryOp(getOpcode())) +return vputils::onlyFirstLaneUsed(this); + + switch (getOpcode()) { + default: +return false; + case Instruction::ICmp: +return vputils::onlyFirstLaneUsed(this); + case VPInstruction::ActiveLaneMask: + case VPInstruction::CalculateTripCountMinusVF: + case VPInstruction::CanonicalIVIncrementForPart: + case VPInstruction::BranchOnCount: +return getOperand(0) == Op; + }; + llvm_unreachable("switch should return"); +} #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPInstruction::dump() const { diff --git a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll index e81fb66239bd4..f05ec30619c5d 100644 --- a/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll +++ b/llvm/test/Transforms/LoopVectorize/pr45679-fold-tail-by-masking.ll @@ -67,7 +67,7 @@ define void @pr45679(ptr %A) optsize { ; CHECK-NEXT:store i32 13, ptr [[ARRAYIDX]], align 1 ; CHECK-NEXT:[[RIVPLUS1]] = add nuw nsw i32 [[RIV]], 1 ; CHECK-NEXT:[[COND:%.*]] = icmp eq i32 [[RIVPLUS1]], 14 -; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP2:![0-9]+]] +; CHECK-NEXT:br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP3:![0-9]+]] ; CHECK:
[clang] 6f29941 - [TBAA] Add extra tests to copy structs with union members.
Author: Florian Hahn Date: 2024-03-07T18:57:09Z New Revision: 6f299417769ade1635c91f974a8745e237cc9adf URL: https://github.com/llvm/llvm-project/commit/6f299417769ade1635c91f974a8745e237cc9adf DIFF: https://github.com/llvm/llvm-project/commit/6f299417769ade1635c91f974a8745e237cc9adf.diff LOG: [TBAA] Add extra tests to copy structs with union members. Adds extra test coverage for TBAA generation for copies of structs with union members. Added: Modified: clang/test/CodeGen/tbaa-struct.cpp Removed: diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index 883c982be26c8f..63e4097946448e 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -151,6 +151,38 @@ void copy10(NamedBitfields3 *a1, NamedBitfields3 *a2) { *a1 = *a2; } +union U2 { + double d; + float f; +}; + +struct UnionMember1 { + U2 u; + int p; +}; + +void copy11(UnionMember1 *a1, UnionMember1 *a2) { +// CHECK-LABEL: _Z6copy11P12UnionMember1S0_ +// CHECK: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %a1, ptr noundef nonnull align 8 dereferenceable(16) %a2, i64 16, i1 false), +// CHECK-OLD-SAME: !tbaa.struct [[TS9:!.*]] +// CHECK-NEW-SAME: !tbaa [[TAG_UnionMember1:!.+]], !tbaa.struct + *a1 = *a2; +} + +struct UnionMember2 { + int p; + U2 u; +}; + +void copy12(UnionMember2 *a1, UnionMember2 *a2) { +// CHECK-LABEL: _Z6copy12P12UnionMember2S0_ +// CHECK: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %a1, ptr noundef nonnull align 8 dereferenceable(16) %a2, i64 16, i1 false), +// CHECK-OLD-SAME: !tbaa.struct [[TS10:!.*]] +// CHECK-NEW-SAME: !tbaa [[TAG_UnionMember2:!.+]], !tbaa.struct + + *a1 = *a2; +} + // CHECK-OLD: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}} // CHECK-OLD: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}} // CHECK-OLD: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0} @@ -167,6 +199,10 @@ void copy10(NamedBitfields3 *a1, NamedBitfields3 *a2) { // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} // CHECK-OLD: [[TS7]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]], i64 3, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE]], i64 16, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS8]] = !{i64 0, i64 4, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE]]} +// CHECK-OLD: [[TS9]] = !{i64 0, i64 8, [[TAG_DOUBLE]], i64 0, i64 4, [[TAG_FLOAT:!.+]], i64 8, i64 4, [[TAG_INT]]} +// CHECK-OLD: [[TAG_FLOAT]] = !{[[FLOAT:!.+]], [[FLOAT]], i64 0} +// CHECK-OLD: [[FLOAT]] = !{!"float", [[CHAR]], i64 0} +// CHECK-OLD: [[TS10]] = !{i64 0, i64 4, [[TAG_INT]], i64 8, i64 8, [[TAG_DOUBLE]], i64 8, i64 4, [[TAG_FLOAT:!.+]]} // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"} // CHECK-NEW-DAG: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 0} @@ -188,3 +224,7 @@ void copy10(NamedBitfields3 *a1, NamedBitfields3 *a2) { // CHECK-NEW-DAG: [[TYPE_NamedBitfields2]] = !{[[TYPE_char]], i64 24, !"_ZTS15NamedBitfields2", [[TYPE_char]], i64 0, i64 1, [[TYPE_char]], i64 1, i64 1, [[TYPE_char]], i64 2, i64 1, [[TYPE_int]], i64 3, i64 4, [[TYPE_int]], i64 3, i64 4, [[TYPE_char]], i64 4, i64 1, [[TYPE_double]], i64 8, i64 8, [[TYPE_int]], i64 16, i64 4} // CHECK-NEW-DAG: [[TAG_NamedBitfields3]] = !{[[TYPE_NamedBitfields3:!.+]], [[TYPE_NamedBitfields3]], i64 0, i64 16} // CHECK-NEW-DAG: [[TYPE_NamedBitfields3]] = !{[[TYPE_char]], i64 16, !"_ZTS15NamedBitfields3", [[TYPE_int]], i64 1, i64 4, [[TYPE_int]], i64 2, i64 4, [[TYPE_double]], i64 8, i64 8} +// CHECK-NEW-DAG: [[TAG_UnionMember1]] = !{[[TYPE_UnionMember1:!.+]], [[TYPE_UnionMember1]], i64 0, i64 16} +// CHECK-NEW-DAG: [[TYPE_UnionMember1]] = !{[[TYPE_char]], i64 16, !"_ZTS12UnionMember1", [[TYPE_char]], i64 0, i64 8, [[TYPE_int]], i64 8, i64 4} +// CHECK-NEW-DAG: [[TAG_UnionMember2]] = !{[[TYPE_UnionMember2:!.+]], [[TYPE_UnionMember2]], i64 0, i64 16} +// CHECK-NEW-DAG: [[TYPE_UnionMember2]] = !{[[TYPE_char]], i64 16, !"_ZTS12UnionMember2", [[TYPE_int]], i64 0, i64 4, [[TYPE_char]], i64 8, i64 8} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Generate tbaa.struct single field with char tag for unions. (PR #84370)
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/84370 At the moment,distinct fields for each union member are generated. When copying a union, we don't know which union member is active, so there's no benefit from recording the different fields. It can result in converting tbaa.struct fields to incorrect tbaa nodes when extracting fields. >From 379844ae4a78d13ca80a12ee34338a53723ffab4 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 7 Mar 2024 16:28:00 + Subject: [PATCH] [TBAA] Generate tbaa.struct single field with char tag for unions. At the moment,distinct fields for each union member are generated. When copying a union, we don't know which union member is active, so there's no benefit from recording the different fields. It can also result in converting tbaa.struct fields to incorrect tbaa nodes when extracting fields. --- clang/lib/CodeGen/CodeGenTBAA.cpp | 8 clang/test/CodeGen/tbaa-struct.cpp | 8 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 8a081612193978..69fb1e11edc7dc 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -286,6 +286,14 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, /* Things not handled yet include: C++ base classes, bitfields, */ if (const RecordType *TTy = QTy->getAs()) { +if (TTy->isUnionType()) { + uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity(); + llvm::MDNode *TBAAType = getChar(); + llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size)); + Fields.push_back( + llvm::MDBuilder::TBAAStructField(BaseOffset, Size, TBAATag)); + return true; +} const RecordDecl *RD = TTy->getDecl()->getDefinition(); if (RD->hasFlexibleArrayMember()) return false; diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index 63e4097946448e..9b4b7415142d93 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -191,7 +191,7 @@ void copy12(UnionMember2 *a1, UnionMember2 *a2) { // (offset, size) = (0,1) char; (4,2) short; (8,4) int; (12,1) char; (16,4) int; (20,4) int // CHECK-OLD: [[TS2]] = !{i64 0, i64 1, !{{.*}}, i64 4, i64 2, !{{.*}}, i64 8, i64 4, !{{.*}}, i64 12, i64 1, !{{.*}}, i64 16, i64 4, {{.*}}, i64 20, i64 4, {{.*}}} // (offset, size) = (0,8) char; (0,2) char; (4,8) char -// CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}} +// CHECK-OLD: [[TS3]] = !{i64 0, i64 12, [[TAG_CHAR]]} // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS6]] = !{i64 0, i64 2, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} @@ -199,10 +199,8 @@ void copy12(UnionMember2 *a1, UnionMember2 *a2) { // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} // CHECK-OLD: [[TS7]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]], i64 3, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE]], i64 16, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS8]] = !{i64 0, i64 4, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE]]} -// CHECK-OLD: [[TS9]] = !{i64 0, i64 8, [[TAG_DOUBLE]], i64 0, i64 4, [[TAG_FLOAT:!.+]], i64 8, i64 4, [[TAG_INT]]} -// CHECK-OLD: [[TAG_FLOAT]] = !{[[FLOAT:!.+]], [[FLOAT]], i64 0} -// CHECK-OLD: [[FLOAT]] = !{!"float", [[CHAR]], i64 0} -// CHECK-OLD: [[TS10]] = !{i64 0, i64 4, [[TAG_INT]], i64 8, i64 8, [[TAG_DOUBLE]], i64 8, i64 4, [[TAG_FLOAT:!.+]]} +// CHECK-OLD: [[TS9]] = !{i64 0, i64 8, [[TAG_CHAR]], i64 8, i64 4, [[TAG_INT]]} +// CHECK-OLD: [[TS10]] = !{i64 0, i64 4, [[TAG_INT]], i64 8, i64 8, [[TAG_CHAR]]} // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"} // CHECK-NEW-DAG: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 0} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 167b90d - [TBAA] Add test showing tbaa.struct being generated with relaxed-alias.
Author: Florian Hahn Date: 2024-03-07T21:40:23Z New Revision: 167b90d0401d0fe488195c7e3d6fc1edc8fc5d94 URL: https://github.com/llvm/llvm-project/commit/167b90d0401d0fe488195c7e3d6fc1edc8fc5d94 DIFF: https://github.com/llvm/llvm-project/commit/167b90d0401d0fe488195c7e3d6fc1edc8fc5d94.diff LOG: [TBAA] Add test showing tbaa.struct being generated with relaxed-alias. Add test showing that tbaa.struct is generated when using TSan with relaxed-aliasing. Added: clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp Modified: Removed: diff --git a/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp b/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp new file mode 100644 index 00..931ff2476cd1bb --- /dev/null +++ b/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - -O1 -relaxed-aliasing -fsanitize=thread -disable-llvm-optzns %s | \ +// RUN: FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -new-struct-path-tbaa \ +// RUN: -emit-llvm -o - -O1 -relaxed-aliasing -fsanitize=thread -disable-llvm-optzns %s | \ +// RUN: FileCheck %s +// +// Check that we do not create tbaa for instructions generated for copies. +// FIXME: !tbaa.struct is generated with null node as tag. + +// CHECK: !tbaa.struct +// CHECK-NOT: !tbaa + +struct A { + short s; + int i; + char c; + int j; +}; + +void copyStruct(A *a1, A *a2) { + *a1 = *a2; +} + +void copyInt(int *a, int *b) { + *a = *b; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Add bail-out to skip tbaa generation to getTBAAStructInfo. (PR #84386)
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/84386 Without this bail out, we may generate fields with null nodes as tags are generated by using getTypeInfo which has the same bail out. >From 36144a7b2a84b10711904c1a568bf02554f83296 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 7 Mar 2024 21:45:49 + Subject: [PATCH] [TBAA] Add bail-out to skip tbaa generation to getTBAAStructInfo. Without this bail out, we may generate fields with null nodes as tags are generated by using getTypeInfo which has the same bail out. --- clang/lib/CodeGen/CodeGenTBAA.cpp | 3 +++ clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 8a081612193978..1f07205a5af225 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -343,6 +343,9 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, llvm::MDNode * CodeGenTBAA::getTBAAStructInfo(QualType QTy) { + if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing) +return nullptr; + const Type *Ty = Context.getCanonicalType(QTy).getTypePtr(); if (llvm::MDNode *N = StructMetadataCache[Ty]) diff --git a/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp b/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp index 931ff2476cd1bb..ce613b9d6b23f8 100644 --- a/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp +++ b/clang/test/CodeGen/tbaa-struct-relaxed-aliasing-with-tsan.cpp @@ -5,9 +5,7 @@ // RUN: FileCheck %s // // Check that we do not create tbaa for instructions generated for copies. -// FIXME: !tbaa.struct is generated with null node as tag. -// CHECK: !tbaa.struct // CHECK-NOT: !tbaa struct A { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Add bail-out to skip tbaa generation to getTBAAStructInfo. (PR #84386)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/84386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Generate tbaa.struct single field with char tag for unions. (PR #84370)
fhahn wrote: ping :) (apologies for early ping, but I'd like to bump this as this is a potential mis-compile I think( https://github.com/llvm/llvm-project/pull/84370 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Generate tbaa.struct single field with char tag for unions. (PR #84370)
fhahn wrote: > Do you have a testcase that shows how this goes wrong without this change ? I am not 100% if the type-based aliasing rules allow aliasing a union access containing a float and a plain pointer to float, but I am thinking about something like the below, where we remove the first store to `f`, even though `f` may alias the union if the float is selected. Again, not sure if that's 100% within the C/C++ type-based aliasing rules, but it is what I could construct easily. Irrespective of this it should show how the TBAA tags for the load of `u` incorrectly claims it is loading an int. ``` union U2 { int d; float f; }; struct UnionMember2 { int p; U2 u; }; void use(int, U2); void copy12( UnionMember2 *a2, float *f) { *f = 1.0; UnionMember2 a1 = *a2; int p = a1.p; U2 u = a1.u; *f = 2.0; use(p, u); } ``` https://clang.godbolt.org/z/Y6PPWEo69 https://github.com/llvm/llvm-project/pull/84370 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Generate tbaa.struct single field with char tag for unions. (PR #84370)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/84370 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7110147 - [TBAA] Test for tbaa.struct creation for struct with named bitfields.
Author: Florian Hahn Date: 2024-02-25T13:17:08Z New Revision: 711014714716753f791291ed6a152e00899469a3 URL: https://github.com/llvm/llvm-project/commit/711014714716753f791291ed6a152e00899469a3 DIFF: https://github.com/llvm/llvm-project/commit/711014714716753f791291ed6a152e00899469a3.diff LOG: [TBAA] Test for tbaa.struct creation for struct with named bitfields. Add test for tbaa.struct metadata creation for copies of a struct with named bitfields. Test for https://github.com/llvm/llvm-project/issues/82586. Added: Modified: clang/test/CodeGen/tbaa-struct.cpp Removed: diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index 47ccec3fb4162a..ff5521fcf3f604 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -102,6 +102,23 @@ void copy7(A *a1, AA *a2) { *a1 = *a2; } +struct NamedBitfields { + signed f0 : 9; + unsigned f1 : 2; + char f2; + double f3; +}; + +NamedBitfields g; + +void copy8(NamedBitfields *a1, NamedBitfields *a2) { +// CHECK-LABEL: _Z5copy8P14NamedBitfieldsS0_ +// CHECK: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %a1, ptr noundef nonnull align 8 dereferenceable(16) %a2, i64 16, i1 false), +// CHECK-OLD-SAME: !tbaa.struct [[TS6:!.*]] +// CHECK-NEW-SAME: !tbaa [[TAG_NamedBitfields:!.+]], !tbaa.struct + *a1 = *a2; +} + // CHECK-OLD: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}} // CHECK-OLD: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}} // CHECK-OLD: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0} @@ -113,6 +130,9 @@ void copy7(A *a1, AA *a2) { // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}} // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]} +// CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} +// CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} +// CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"} // CHECK-NEW-DAG: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 0} @@ -127,3 +147,6 @@ void copy7(A *a1, AA *a2) { // CHECK-NEW-DAG: [[TAG_C]] = !{[[TYPE_C]], [[TYPE_C]], i64 0, i64 3} // CHECK-NEW-DAG: [[TYPE_D:!.*]] = !{[[TYPE_char]], i64 6, !"_ZTS1D", [[TYPE_char]], i64 0, i64 1, [[TYPE_char]], i64 4, i64 1, [[TYPE_char]], i64 5, i64 1} // CHECK-NEW-DAG: [[TAG_D]] = !{[[TYPE_D]], [[TYPE_D]], i64 0, i64 6} +// CHECK-NEW-DAG: [[TAG_NamedBitfields]] = !{[[TYPE_NamedBitfields:!.+]], [[TYPE_NamedBitfields]], i64 0, i64 16} +// CHECK-NEW-DAG: [[TYPE_NamedBitfields]] = !{[[TYPE_char]], i64 16, !"_ZTS14NamedBitfields", [[TYPE_int]], i64 0, i64 4, [[TYPE_int]], i64 1, i64 4, [[TYPE_char]], i64 2, i64 1, [[TYPE_double:!.+]], i64 8, i64 8} +// CHECK-NEW-DAG: [[TYPE_double]] = !{[[TYPE_char]], i64 8, !"double"} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/82922 At the moment, clang generates what I believe are incorrect !tbaa.struct fields for named bitfields. At the moment, the base type size is used for named bifields (e.g. sizeof(int)) instead of the bifield width per field. This results in overalpping fields in !tbaa.struct metadata. This causes incorrect results when extracting individual copied fields from !tbaa.struct as in added in dc85719d5. This patch fixes that by skipping all bitfields, not only unnamed ones (note that CollectFields has a TODO to support bitfields). As bitfields specify their widths in bits, while !tbaa metadata uses bytes for sizes and offsets, I don't think we would be able to generate correct metadata for them in general. If this understanding is correct, I can also extend the verifier to check that !tbaa.struct fields aren't overlapping. Fixes https://github.com/llvm/llvm-project/issues/82586 >From 556fcefed9645aa0a0a965ff8f22d8accdf9eefc Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 25 Feb 2024 13:23:17 + Subject: [PATCH] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. At the moment, clang generates what I believe are incorrect !tbaa.struct fields for named bitfields. At the moment, the base type size is used for named bifields (e.g. sizeof(int)) instead of the bifield width per field. This results in overalpping fields in !tbaa.struct metadata. This causes incorrect results when extracting individual copied fields from !tbaa.struct as in added in dc85719d5. This patch fixes that by skipping all bitfields, not only unnamed ones (note that CollectFields has a TODO to support bitfields). As bitfields specify their widths in bits, while !tbaa metadata uses bytes for sizes and offsets, I don't think we would be able to generate correct metadata for them in general. If this understanding is correct, I can also extend the verifier to check that !tbaa.struct fields aren't overlapping. Fixes https://github.com/llvm/llvm-project/issues/82586 --- clang/lib/CodeGen/CodeGenTBAA.cpp | 2 +- clang/test/CodeGen/tbaa-struct.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index dc288bc3f6157a..43a1aee3d73823 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -298,7 +298,7 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, unsigned idx = 0; for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i, ++idx) { - if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield()) + if ((*i)->isZeroSize(Context) || (*i)->isBitField()) continue; uint64_t Offset = BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth(); diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index ff5521fcf3f604..17c9d6bf6a7260 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -130,7 +130,7 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}} // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]} -// CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} +// CHECK-OLD: [[TS6]] = !{i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} // CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/82922 >From 556fcefed9645aa0a0a965ff8f22d8accdf9eefc Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 25 Feb 2024 13:23:17 + Subject: [PATCH 1/2] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. At the moment, clang generates what I believe are incorrect !tbaa.struct fields for named bitfields. At the moment, the base type size is used for named bifields (e.g. sizeof(int)) instead of the bifield width per field. This results in overalpping fields in !tbaa.struct metadata. This causes incorrect results when extracting individual copied fields from !tbaa.struct as in added in dc85719d5. This patch fixes that by skipping all bitfields, not only unnamed ones (note that CollectFields has a TODO to support bitfields). As bitfields specify their widths in bits, while !tbaa metadata uses bytes for sizes and offsets, I don't think we would be able to generate correct metadata for them in general. If this understanding is correct, I can also extend the verifier to check that !tbaa.struct fields aren't overlapping. Fixes https://github.com/llvm/llvm-project/issues/82586 --- clang/lib/CodeGen/CodeGenTBAA.cpp | 2 +- clang/test/CodeGen/tbaa-struct.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index dc288bc3f6157a..43a1aee3d73823 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -298,7 +298,7 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, unsigned idx = 0; for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i, ++idx) { - if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield()) + if ((*i)->isZeroSize(Context) || (*i)->isBitField()) continue; uint64_t Offset = BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth(); diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index ff5521fcf3f604..17c9d6bf6a7260 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -130,7 +130,7 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}} // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]} -// CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} +// CHECK-OLD: [[TS6]] = !{i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} // CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} >From 32be3b7d944fc5da50add4b6fea551ba6c9d428c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 26 Feb 2024 10:19:57 + Subject: [PATCH 2/2] WIP use CGBitFieldInfo. --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- clang/lib/CodeGen/CodeGenTBAA.cpp | 33 +++-- clang/lib/CodeGen/CodeGenTBAA.h | 4 +++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 95e457bef28ed3..ed8db055723024 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -397,7 +397,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0. if (LangOpts.Sanitize.has(SanitizerKind::Thread) || (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)) -TBAA.reset(new CodeGenTBAA(Context, TheModule, CodeGenOpts, getLangOpts(), +TBAA.reset(new CodeGenTBAA(Context, getTypes(), TheModule, CodeGenOpts, getLangOpts(), getCXXABI().getMangleContext())); // If debug info or coverage generation is enabled, create the CGDebugInfo diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 43a1aee3d73823..6a453bb1144582 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -14,6 +14,8 @@ // //===--===// +#include "CGRecordLayout.h" +#include "CodeGenTypes.h" #include "CodeGenTBAA.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" @@ -29,10 +31,10 @@ using namespace clang; using namespace CodeGen; -CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::Module &M, +CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M, const CodeGenOptions &CGO, const LangOptions &Features, MangleContext &MContext) - : Contex
[clang] f290c00 - [TBAA] Add additional bitfield tests.
Author: Florian Hahn Date: 2024-02-26T12:36:00Z New Revision: f290c000d87bfc72a31b151dffa2d190596ebe91 URL: https://github.com/llvm/llvm-project/commit/f290c000d87bfc72a31b151dffa2d190596ebe91 DIFF: https://github.com/llvm/llvm-project/commit/f290c000d87bfc72a31b151dffa2d190596ebe91.diff LOG: [TBAA] Add additional bitfield tests. Additional test for https://github.com/llvm/llvm-project/pull/82922/. Added: Modified: clang/test/CodeGen/tbaa-struct.cpp Removed: diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index ff5521fcf3f604..e25fbc1a778103 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -109,8 +109,6 @@ struct NamedBitfields { double f3; }; -NamedBitfields g; - void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-LABEL: _Z5copy8P14NamedBitfieldsS0_ // CHECK: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %a1, ptr noundef nonnull align 8 dereferenceable(16) %a2, i64 16, i1 false), @@ -119,6 +117,23 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { *a1 = *a2; } +struct NamedBitfields2 { + char a, b, c; + signed f0 : 3; + unsigned f1 : 4; + char f2 : 7; + double f3; + unsigned f4 : 4; +}; + +void copy9(NamedBitfields2 *a1, NamedBitfields2 *a2) { +// CHECK-LABEL: _Z5copy9P15NamedBitfields2S0_ +// CHECK: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %a1, ptr noundef nonnull align 8 dereferenceable(24) %a2, i64 24, i1 false), +// CHECK-OLD-SAME: !tbaa.struct [[TS7:!.*]] +// CHECK-NEW-SAME: !tbaa [[TAG_NamedBitfields2:!.+]], !tbaa.struct + *a1 = *a2; +} + // CHECK-OLD: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}} // CHECK-OLD: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}} // CHECK-OLD: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0} @@ -133,6 +148,7 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} // CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} +// CHECK-OLD: [[TS7]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]], i64 3, i64 4, [[TAG_INT]], i64 3, i64 4, [[TAG_INT]], i64 4, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE]], i64 16, i64 4, [[TAG_INT]]} // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"} // CHECK-NEW-DAG: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 0} @@ -150,3 +166,5 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-NEW-DAG: [[TAG_NamedBitfields]] = !{[[TYPE_NamedBitfields:!.+]], [[TYPE_NamedBitfields]], i64 0, i64 16} // CHECK-NEW-DAG: [[TYPE_NamedBitfields]] = !{[[TYPE_char]], i64 16, !"_ZTS14NamedBitfields", [[TYPE_int]], i64 0, i64 4, [[TYPE_int]], i64 1, i64 4, [[TYPE_char]], i64 2, i64 1, [[TYPE_double:!.+]], i64 8, i64 8} // CHECK-NEW-DAG: [[TYPE_double]] = !{[[TYPE_char]], i64 8, !"double"} +// CHECK-NEW-DAG: [[TAG_NamedBitfields2]] = !{[[TYPE_NamedBitfields2:!.+]], [[TYPE_NamedBitfields2]], i64 0, i64 24} +// CHECK-NEW-DAG: [[TYPE_NamedBitfields2]] = !{[[TYPE_char]], i64 24, !"_ZTS15NamedBitfields2", [[TYPE_char]], i64 0, i64 1, [[TYPE_char]], i64 1, i64 1, [[TYPE_char]], i64 2, i64 1, [[TYPE_int]], i64 3, i64 4, [[TYPE_int]], i64 3, i64 4, [[TYPE_char]], i64 4, i64 1, [[TYPE_double]], i64 8, i64 8, [[TYPE_int]], i64 16, i64 4} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/82922 >From 556fcefed9645aa0a0a965ff8f22d8accdf9eefc Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 25 Feb 2024 13:23:17 + Subject: [PATCH 1/5] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. At the moment, clang generates what I believe are incorrect !tbaa.struct fields for named bitfields. At the moment, the base type size is used for named bifields (e.g. sizeof(int)) instead of the bifield width per field. This results in overalpping fields in !tbaa.struct metadata. This causes incorrect results when extracting individual copied fields from !tbaa.struct as in added in dc85719d5. This patch fixes that by skipping all bitfields, not only unnamed ones (note that CollectFields has a TODO to support bitfields). As bitfields specify their widths in bits, while !tbaa metadata uses bytes for sizes and offsets, I don't think we would be able to generate correct metadata for them in general. If this understanding is correct, I can also extend the verifier to check that !tbaa.struct fields aren't overlapping. Fixes https://github.com/llvm/llvm-project/issues/82586 --- clang/lib/CodeGen/CodeGenTBAA.cpp | 2 +- clang/test/CodeGen/tbaa-struct.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index dc288bc3f6157a..43a1aee3d73823 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -298,7 +298,7 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, unsigned idx = 0; for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i, ++idx) { - if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield()) + if ((*i)->isZeroSize(Context) || (*i)->isBitField()) continue; uint64_t Offset = BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth(); diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index ff5521fcf3f604..17c9d6bf6a7260 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -130,7 +130,7 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}} // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]} -// CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} +// CHECK-OLD: [[TS6]] = !{i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} // CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} >From 32be3b7d944fc5da50add4b6fea551ba6c9d428c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 26 Feb 2024 10:19:57 + Subject: [PATCH 2/5] WIP use CGBitFieldInfo. --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- clang/lib/CodeGen/CodeGenTBAA.cpp | 33 +++-- clang/lib/CodeGen/CodeGenTBAA.h | 4 +++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 95e457bef28ed3..ed8db055723024 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -397,7 +397,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0. if (LangOpts.Sanitize.has(SanitizerKind::Thread) || (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)) -TBAA.reset(new CodeGenTBAA(Context, TheModule, CodeGenOpts, getLangOpts(), +TBAA.reset(new CodeGenTBAA(Context, getTypes(), TheModule, CodeGenOpts, getLangOpts(), getCXXABI().getMangleContext())); // If debug info or coverage generation is enabled, create the CGDebugInfo diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 43a1aee3d73823..6a453bb1144582 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -14,6 +14,8 @@ // //===--===// +#include "CGRecordLayout.h" +#include "CodeGenTypes.h" #include "CodeGenTBAA.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" @@ -29,10 +31,10 @@ using namespace clang; using namespace CodeGen; -CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::Module &M, +CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M, const CodeGenOptions &CGO, const LangOptions &Features, MangleContext &MContext) - : Contex
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
fhahn wrote: > This seems like it messes up the metadata in a different way: we have no > representation of the bitfield at all, so it looks like it's padding. > > I think we want to treat multiple adjacent bitfields as a single "field". So > NamedBitfields from the testcase would have three fields in the LLVM TBAA > data: one "field" containing both bitfields, followed by a field for the > char, followed by a field for the double. You should be able to use > CGBitFieldInfo for this, I think? Thanks, updated the patch as suggested. https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 54cff50 - [TBAA] Add !tbaa.struct test with unnamed bitfields.
Author: Florian Hahn Date: 2024-02-26T22:50:50Z New Revision: 54cff50791dec977feb0badb74919d97dff5b859 URL: https://github.com/llvm/llvm-project/commit/54cff50791dec977feb0badb74919d97dff5b859 DIFF: https://github.com/llvm/llvm-project/commit/54cff50791dec977feb0badb74919d97dff5b859.diff LOG: [TBAA] Add !tbaa.struct test with unnamed bitfields. Extra tests with unnamed bitfields for https://github.com/llvm/llvm-project/pull/82922. Added: Modified: clang/test/CodeGen/tbaa-struct.cpp Removed: diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index e25fbc1a778103..28c7d396121af4 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -134,6 +134,23 @@ void copy9(NamedBitfields2 *a1, NamedBitfields2 *a2) { *a1 = *a2; } +// Test with unnamed bitfield at the start and in between named ones.. +struct NamedBitfields3 { + unsigned : 11; + signed f0 : 9; + char : 2; + int f1 : 2; + double f2; +}; + +void copy10(NamedBitfields3 *a1, NamedBitfields3 *a2) { +// CHECK-LABEL: _Z6copy10P15NamedBitfields3S0_ +// CHECK: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %a1, ptr noundef nonnull align 8 dereferenceable(16) %a2, i64 16, i1 false), +// CHECK-OLD-SAME: !tbaa.struct [[TS8:!.*]] +// CHECK-NEW-SAME: !tbaa [[TAG_NamedBitfields3:!.+]], !tbaa.struct + *a1 = *a2; +} + // CHECK-OLD: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}} // CHECK-OLD: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}} // CHECK-OLD: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0} @@ -149,6 +166,7 @@ void copy9(NamedBitfields2 *a1, NamedBitfields2 *a2) { // CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} // CHECK-OLD: [[TS7]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]], i64 3, i64 4, [[TAG_INT]], i64 3, i64 4, [[TAG_INT]], i64 4, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE]], i64 16, i64 4, [[TAG_INT]]} +// CHECK-OLD: [[TS8]] = !{i64 1, i64 4, [[TAG_INT]], i64 2, i64 4, [[TAG_INT]], i64 8, i64 8, [[TAG_DOUBLE]]} // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"} // CHECK-NEW-DAG: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 0} @@ -168,3 +186,5 @@ void copy9(NamedBitfields2 *a1, NamedBitfields2 *a2) { // CHECK-NEW-DAG: [[TYPE_double]] = !{[[TYPE_char]], i64 8, !"double"} // CHECK-NEW-DAG: [[TAG_NamedBitfields2]] = !{[[TYPE_NamedBitfields2:!.+]], [[TYPE_NamedBitfields2]], i64 0, i64 24} // CHECK-NEW-DAG: [[TYPE_NamedBitfields2]] = !{[[TYPE_char]], i64 24, !"_ZTS15NamedBitfields2", [[TYPE_char]], i64 0, i64 1, [[TYPE_char]], i64 1, i64 1, [[TYPE_char]], i64 2, i64 1, [[TYPE_int]], i64 3, i64 4, [[TYPE_int]], i64 3, i64 4, [[TYPE_char]], i64 4, i64 1, [[TYPE_double]], i64 8, i64 8, [[TYPE_int]], i64 16, i64 4} +// CHECK-NEW-DAG: [[TAG_NamedBitfields3]] = !{[[TYPE_NamedBitfields3:!.+]], [[TYPE_NamedBitfields3]], i64 0, i64 16} +// CHECK-NEW-DAG: [[TYPE_NamedBitfields3]] = !{[[TYPE_char]], i64 16, !"_ZTS15NamedBitfields3", [[TYPE_int]], i64 1, i64 4, [[TYPE_int]], i64 2, i64 4, [[TYPE_double]], i64 8, i64 8} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/82922 >From 556fcefed9645aa0a0a965ff8f22d8accdf9eefc Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 25 Feb 2024 13:23:17 + Subject: [PATCH 1/6] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. At the moment, clang generates what I believe are incorrect !tbaa.struct fields for named bitfields. At the moment, the base type size is used for named bifields (e.g. sizeof(int)) instead of the bifield width per field. This results in overalpping fields in !tbaa.struct metadata. This causes incorrect results when extracting individual copied fields from !tbaa.struct as in added in dc85719d5. This patch fixes that by skipping all bitfields, not only unnamed ones (note that CollectFields has a TODO to support bitfields). As bitfields specify their widths in bits, while !tbaa metadata uses bytes for sizes and offsets, I don't think we would be able to generate correct metadata for them in general. If this understanding is correct, I can also extend the verifier to check that !tbaa.struct fields aren't overlapping. Fixes https://github.com/llvm/llvm-project/issues/82586 --- clang/lib/CodeGen/CodeGenTBAA.cpp | 2 +- clang/test/CodeGen/tbaa-struct.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index dc288bc3f6157a..43a1aee3d73823 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -298,7 +298,7 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, unsigned idx = 0; for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i, ++idx) { - if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield()) + if ((*i)->isZeroSize(Context) || (*i)->isBitField()) continue; uint64_t Offset = BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth(); diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index ff5521fcf3f604..17c9d6bf6a7260 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -130,7 +130,7 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}} // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]} -// CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} +// CHECK-OLD: [[TS6]] = !{i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} // CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} >From 32be3b7d944fc5da50add4b6fea551ba6c9d428c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 26 Feb 2024 10:19:57 + Subject: [PATCH 2/6] WIP use CGBitFieldInfo. --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- clang/lib/CodeGen/CodeGenTBAA.cpp | 33 +++-- clang/lib/CodeGen/CodeGenTBAA.h | 4 +++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 95e457bef28ed3..ed8db055723024 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -397,7 +397,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0. if (LangOpts.Sanitize.has(SanitizerKind::Thread) || (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)) -TBAA.reset(new CodeGenTBAA(Context, TheModule, CodeGenOpts, getLangOpts(), +TBAA.reset(new CodeGenTBAA(Context, getTypes(), TheModule, CodeGenOpts, getLangOpts(), getCXXABI().getMangleContext())); // If debug info or coverage generation is enabled, create the CGDebugInfo diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 43a1aee3d73823..6a453bb1144582 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -14,6 +14,8 @@ // //===--===// +#include "CGRecordLayout.h" +#include "CodeGenTypes.h" #include "CodeGenTBAA.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" @@ -29,10 +31,10 @@ using namespace clang; using namespace CodeGen; -CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::Module &M, +CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M, const CodeGenOptions &CGO, const LangOptions &Features, MangleContext &MContext) - : Contex
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
@@ -294,18 +297,49 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, return false; const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); +const CGRecordLayout &CGRL = CGTypes.getCGRecordLayout(RD); unsigned idx = 0; -for (RecordDecl::field_iterator i = RD->field_begin(), - e = RD->field_end(); i != e; ++i, ++idx) { - if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield()) +for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e;) { + if ((*i)->isZeroSize(Context)) { +++i; +++idx; continue; - uint64_t Offset = BaseOffset + -Layout.getFieldOffset(idx) / Context.getCharWidth(); + } + + uint64_t Offset = + BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth(); QualType FieldQTy = i->getType(); + // Create a single field for consecutive named bitfields using char as + // base type. + if ((*i)->isBitField() && !(*i)->isUnnamedBitfield()) { +unsigned CurrentBitFieldSize = 0; +unsigned CurrentBitFieldOffset = CGRL.getBitFieldInfo(*i).Offset; +while (i != e && (*i)->isBitField() && !(*i)->isUnnamedBitfield()) { fhahn wrote: Yes, test showing that added in 54cff50791dec977feb0badb74919d97dff5b859, thanks! https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
@@ -294,18 +297,49 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, return false; const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); +const CGRecordLayout &CGRL = CGTypes.getCGRecordLayout(RD); unsigned idx = 0; -for (RecordDecl::field_iterator i = RD->field_begin(), - e = RD->field_end(); i != e; ++i, ++idx) { - if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield()) +for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e;) { + if ((*i)->isZeroSize(Context)) { +++i; +++idx; continue; - uint64_t Offset = BaseOffset + -Layout.getFieldOffset(idx) / Context.getCharWidth(); + } + + uint64_t Offset = + BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth(); QualType FieldQTy = i->getType(); + // Create a single field for consecutive named bitfields using char as + // base type. + if ((*i)->isBitField() && !(*i)->isUnnamedBitfield()) { +unsigned CurrentBitFieldSize = 0; +unsigned CurrentBitFieldOffset = CGRL.getBitFieldInfo(*i).Offset; +while (i != e && (*i)->isBitField() && !(*i)->isUnnamedBitfield()) { + const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i); + if (CurrentBitFieldSize + CurrentBitFieldOffset != Info.Offset) +break; + CurrentBitFieldSize += Info.Size; fhahn wrote: Thanks, updated the patch to add a field for the first bitfield in the run using its StorageSize, and skip bitfields where the offset in the run isn't 0 (`Offset`). https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/82922 >From 556fcefed9645aa0a0a965ff8f22d8accdf9eefc Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 25 Feb 2024 13:23:17 + Subject: [PATCH 1/7] [TBAA] Skip all bitfields when generating !tbaa.struct metadata. At the moment, clang generates what I believe are incorrect !tbaa.struct fields for named bitfields. At the moment, the base type size is used for named bifields (e.g. sizeof(int)) instead of the bifield width per field. This results in overalpping fields in !tbaa.struct metadata. This causes incorrect results when extracting individual copied fields from !tbaa.struct as in added in dc85719d5. This patch fixes that by skipping all bitfields, not only unnamed ones (note that CollectFields has a TODO to support bitfields). As bitfields specify their widths in bits, while !tbaa metadata uses bytes for sizes and offsets, I don't think we would be able to generate correct metadata for them in general. If this understanding is correct, I can also extend the verifier to check that !tbaa.struct fields aren't overlapping. Fixes https://github.com/llvm/llvm-project/issues/82586 --- clang/lib/CodeGen/CodeGenTBAA.cpp | 2 +- clang/test/CodeGen/tbaa-struct.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index dc288bc3f6157a..43a1aee3d73823 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -298,7 +298,7 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, unsigned idx = 0; for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i, ++idx) { - if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield()) + if ((*i)->isZeroSize(Context) || (*i)->isBitField()) continue; uint64_t Offset = BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth(); diff --git a/clang/test/CodeGen/tbaa-struct.cpp b/clang/test/CodeGen/tbaa-struct.cpp index ff5521fcf3f604..17c9d6bf6a7260 100644 --- a/clang/test/CodeGen/tbaa-struct.cpp +++ b/clang/test/CodeGen/tbaa-struct.cpp @@ -130,7 +130,7 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) { // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}} // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]} // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]} -// CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} +// CHECK-OLD: [[TS6]] = !{i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]} // CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0} // CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0} >From 32be3b7d944fc5da50add4b6fea551ba6c9d428c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 26 Feb 2024 10:19:57 + Subject: [PATCH 2/7] WIP use CGBitFieldInfo. --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- clang/lib/CodeGen/CodeGenTBAA.cpp | 33 +++-- clang/lib/CodeGen/CodeGenTBAA.h | 4 +++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 95e457bef28ed3..ed8db055723024 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -397,7 +397,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0. if (LangOpts.Sanitize.has(SanitizerKind::Thread) || (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)) -TBAA.reset(new CodeGenTBAA(Context, TheModule, CodeGenOpts, getLangOpts(), +TBAA.reset(new CodeGenTBAA(Context, getTypes(), TheModule, CodeGenOpts, getLangOpts(), getCXXABI().getMangleContext())); // If debug info or coverage generation is enabled, create the CGDebugInfo diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 43a1aee3d73823..6a453bb1144582 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -14,6 +14,8 @@ // //===--===// +#include "CGRecordLayout.h" +#include "CodeGenTypes.h" #include "CodeGenTBAA.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" @@ -29,10 +31,10 @@ using namespace clang; using namespace CodeGen; -CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::Module &M, +CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M, const CodeGenOptions &CGO, const LangOptions &Features, MangleContext &MContext) - : Contex
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
fhahn wrote: > Whitespace is weird in a few places; otherwise looks fine. Argh yes, should be fixed in the latest version. Still need to figure out how to make sure all changes are formatted once the branch contains merges (before the format checker complains and shows the commits) https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Handle bitfields when generating !tbaa.struct metadata. (PR #82922)
fhahn wrote: Thanks! https://github.com/llvm/llvm-project/pull/82922 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [flang] [libcxx] [mlir] [clang] [libcxxabi] [openmp] [compiler-rt] [libc] [AArch64] Add custom lowering for load <3 x i8>. (PR #78632)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78632 >From a786cdedc2c9a9898cd0b80d84f5b11aace5da1c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Tue, 28 Nov 2023 15:44:02 + Subject: [PATCH 01/10] [AArch64] Add custom lowering for load <3 x i8>. Add custom combine to lower load <3 x i8> as the more efficient sequence below: ldrb wX, [x0, #2] ldrh wY, [x0] orr wX, wY, wX, lsl #16 fmov s0, wX At the moment, there are almost no cases in which such vector operations will be generated automatically. The motivating case is non-power-of-2 SLP vectorization: https://github.com/llvm/llvm-project/pull/77790 --- .../Target/AArch64/AArch64ISelLowering.cpp| 54 ++- .../AArch64/vec3-loads-ext-trunc-stores.ll| 44 +-- 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 8a6f1dc7487b..e1139c2fede8 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -21095,6 +21095,50 @@ static SDValue foldTruncStoreOfExt(SelectionDAG &DAG, SDNode *N) { return SDValue(); } +// A custom combine to lower load <3 x i8> as the more efficient sequence +// below: +//ldrb wX, [x0, #2] +//ldrh wY, [x0] +//orr wX, wY, wX, lsl #16 +//fmov s0, wX +// +static SDValue combineV3I8LoadExt(LoadSDNode *LD, SelectionDAG &DAG) { + EVT MemVT = LD->getMemoryVT(); + if (MemVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3) || + LD->getOriginalAlign() >= 4) +return SDValue(); + + SDLoc DL(LD); + SDValue Chain = LD->getChain(); + SDValue BasePtr = LD->getBasePtr(); + + // Load 2 x i8, then 1 x i8. + SDValue L16 = DAG.getLoad(MVT::i16, DL, Chain, BasePtr, LD->getPointerInfo(), +LD->getOriginalAlign()); + SDValue L8 = + DAG.getLoad(MVT::i8, DL, Chain, + DAG.getMemBasePlusOffset(BasePtr, TypeSize::getFixed(2), DL), + LD->getPointerInfo(), LD->getOriginalAlign()); + + // Extend to i32. + SDValue Ext16 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, L16); + SDValue Ext8 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, L8); + + // Pack 2 x i8 and 1 x i8 in an i32 and convert to v4i8. + SDValue Shr = DAG.getNode(ISD::SHL, DL, MVT::i32, Ext8, +DAG.getConstant(16, DL, MVT::i32)); + SDValue Or = DAG.getNode(ISD::OR, DL, MVT::i32, Ext16, Shr); + SDValue Cast = DAG.getNode(ISD::BITCAST, DL, MVT::v4i8, Or); + + // Extract v3i8 again. + SDValue Extract = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MemVT, Cast, +DAG.getConstant(0, DL, MVT::i64)); + SDValue TokenFactor = DAG.getNode( + ISD::TokenFactor, DL, MVT::Other, + {SDValue(cast(L16), 1), SDValue(cast(L8), 1)}); + return DAG.getMergeValues({Extract, TokenFactor}, DL); +} + // Perform TBI simplification if supported by the target and try to break up // nontemporal loads larger than 256-bits loads for odd types so LDNPQ 256-bit // load instructions can be selected. @@ -21106,10 +21150,16 @@ static SDValue performLOADCombine(SDNode *N, performTBISimplification(N->getOperand(1), DCI, DAG); LoadSDNode *LD = cast(N); - EVT MemVT = LD->getMemoryVT(); - if (LD->isVolatile() || !LD->isNonTemporal() || !Subtarget->isLittleEndian()) + if (LD->isVolatile() || !Subtarget->isLittleEndian()) +return SDValue(N, 0); + + if (SDValue Res = combineV3I8LoadExt(LD, DAG)) +return Res; + + if (!LD->isNonTemporal()) return SDValue(N, 0); + EVT MemVT = LD->getMemoryVT(); if (MemVT.isScalableVector() || MemVT.getSizeInBits() <= 256 || MemVT.getSizeInBits() % 256 == 0 || 256 % MemVT.getScalarSizeInBits() != 0) diff --git a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll index 9eeb194409df..7cac4134f0e1 100644 --- a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll +++ b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll @@ -5,19 +5,10 @@ define <16 x i8> @load_v3i8(ptr %src, ptr %dst) { ; CHECK-LABEL: load_v3i8: ; CHECK: ; %bb.0: -; CHECK-NEXT:sub sp, sp, #16 -; CHECK-NEXT:.cfi_def_cfa_offset 16 -; CHECK-NEXT:ldrh w8, [x0] -; CHECK-NEXT:strh w8, [sp, #12] -; CHECK-NEXT:ldr s0, [sp, #12] -; CHECK-NEXT:ushll.8h v0, v0, #0 -; CHECK-NEXT:umov.h w8, v0[0] -; CHECK-NEXT:umov.h w9, v0[1] +; CHECK-NEXT:ldrb w8, [x0, #2] +; CHECK-NEXT:ldrh w9, [x0] +; CHECK-NEXT:orr w8, w9, w8, lsl #16 ; CHECK-NEXT:fmov s0, w8 -; CHECK-NEXT:add x8, x0, #2 -; CHECK-NEXT:mov.b v0[1], w9 -; CHECK-NEXT:ld1.b { v0 }[2], [x8] -; CHECK-NEXT:add sp, sp, #16 ; CHECK-NEXT:ret ; ; BE-LABEL: load_v3i8: @@ -47,19 +38,14 @@ define <16 x i8> @load_v3i8(ptr %src, ptr %dst) { define <4 x i32> @load_v3i8_to_4xi32(ptr %src, ptr %dst) {
[llvm] [clang-tools-extra] [flang] [libcxx] [mlir] [clang] [libcxxabi] [openmp] [compiler-rt] [libc] [AArch64] Add custom lowering for load <3 x i8>. (PR #78632)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78632 >From a786cdedc2c9a9898cd0b80d84f5b11aace5da1c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Tue, 28 Nov 2023 15:44:02 + Subject: [PATCH 01/11] [AArch64] Add custom lowering for load <3 x i8>. Add custom combine to lower load <3 x i8> as the more efficient sequence below: ldrb wX, [x0, #2] ldrh wY, [x0] orr wX, wY, wX, lsl #16 fmov s0, wX At the moment, there are almost no cases in which such vector operations will be generated automatically. The motivating case is non-power-of-2 SLP vectorization: https://github.com/llvm/llvm-project/pull/77790 --- .../Target/AArch64/AArch64ISelLowering.cpp| 54 ++- .../AArch64/vec3-loads-ext-trunc-stores.ll| 44 +-- 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 8a6f1dc7487b..e1139c2fede8 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -21095,6 +21095,50 @@ static SDValue foldTruncStoreOfExt(SelectionDAG &DAG, SDNode *N) { return SDValue(); } +// A custom combine to lower load <3 x i8> as the more efficient sequence +// below: +//ldrb wX, [x0, #2] +//ldrh wY, [x0] +//orr wX, wY, wX, lsl #16 +//fmov s0, wX +// +static SDValue combineV3I8LoadExt(LoadSDNode *LD, SelectionDAG &DAG) { + EVT MemVT = LD->getMemoryVT(); + if (MemVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3) || + LD->getOriginalAlign() >= 4) +return SDValue(); + + SDLoc DL(LD); + SDValue Chain = LD->getChain(); + SDValue BasePtr = LD->getBasePtr(); + + // Load 2 x i8, then 1 x i8. + SDValue L16 = DAG.getLoad(MVT::i16, DL, Chain, BasePtr, LD->getPointerInfo(), +LD->getOriginalAlign()); + SDValue L8 = + DAG.getLoad(MVT::i8, DL, Chain, + DAG.getMemBasePlusOffset(BasePtr, TypeSize::getFixed(2), DL), + LD->getPointerInfo(), LD->getOriginalAlign()); + + // Extend to i32. + SDValue Ext16 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, L16); + SDValue Ext8 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, L8); + + // Pack 2 x i8 and 1 x i8 in an i32 and convert to v4i8. + SDValue Shr = DAG.getNode(ISD::SHL, DL, MVT::i32, Ext8, +DAG.getConstant(16, DL, MVT::i32)); + SDValue Or = DAG.getNode(ISD::OR, DL, MVT::i32, Ext16, Shr); + SDValue Cast = DAG.getNode(ISD::BITCAST, DL, MVT::v4i8, Or); + + // Extract v3i8 again. + SDValue Extract = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MemVT, Cast, +DAG.getConstant(0, DL, MVT::i64)); + SDValue TokenFactor = DAG.getNode( + ISD::TokenFactor, DL, MVT::Other, + {SDValue(cast(L16), 1), SDValue(cast(L8), 1)}); + return DAG.getMergeValues({Extract, TokenFactor}, DL); +} + // Perform TBI simplification if supported by the target and try to break up // nontemporal loads larger than 256-bits loads for odd types so LDNPQ 256-bit // load instructions can be selected. @@ -21106,10 +21150,16 @@ static SDValue performLOADCombine(SDNode *N, performTBISimplification(N->getOperand(1), DCI, DAG); LoadSDNode *LD = cast(N); - EVT MemVT = LD->getMemoryVT(); - if (LD->isVolatile() || !LD->isNonTemporal() || !Subtarget->isLittleEndian()) + if (LD->isVolatile() || !Subtarget->isLittleEndian()) +return SDValue(N, 0); + + if (SDValue Res = combineV3I8LoadExt(LD, DAG)) +return Res; + + if (!LD->isNonTemporal()) return SDValue(N, 0); + EVT MemVT = LD->getMemoryVT(); if (MemVT.isScalableVector() || MemVT.getSizeInBits() <= 256 || MemVT.getSizeInBits() % 256 == 0 || 256 % MemVT.getScalarSizeInBits() != 0) diff --git a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll index 9eeb194409df..7cac4134f0e1 100644 --- a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll +++ b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll @@ -5,19 +5,10 @@ define <16 x i8> @load_v3i8(ptr %src, ptr %dst) { ; CHECK-LABEL: load_v3i8: ; CHECK: ; %bb.0: -; CHECK-NEXT:sub sp, sp, #16 -; CHECK-NEXT:.cfi_def_cfa_offset 16 -; CHECK-NEXT:ldrh w8, [x0] -; CHECK-NEXT:strh w8, [sp, #12] -; CHECK-NEXT:ldr s0, [sp, #12] -; CHECK-NEXT:ushll.8h v0, v0, #0 -; CHECK-NEXT:umov.h w8, v0[0] -; CHECK-NEXT:umov.h w9, v0[1] +; CHECK-NEXT:ldrb w8, [x0, #2] +; CHECK-NEXT:ldrh w9, [x0] +; CHECK-NEXT:orr w8, w9, w8, lsl #16 ; CHECK-NEXT:fmov s0, w8 -; CHECK-NEXT:add x8, x0, #2 -; CHECK-NEXT:mov.b v0[1], w9 -; CHECK-NEXT:ld1.b { v0 }[2], [x8] -; CHECK-NEXT:add sp, sp, #16 ; CHECK-NEXT:ret ; ; BE-LABEL: load_v3i8: @@ -47,19 +38,14 @@ define <16 x i8> @load_v3i8(ptr %src, ptr %dst) { define <4 x i32> @load_v3i8_to_4xi32(ptr %src, ptr %dst) {
[clang-tools-extra] [compiler-rt] [llvm] [libc] [mlir] [libcxxabi] [clang] [flang] [libcxx] [openmp] [AArch64] Add custom lowering for load <3 x i8>. (PR #78632)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/78632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. (PR #79512)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/79512 >From 299a055e271264f918321bf7360ee37c6ede8b26 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Tue, 23 Jan 2024 13:39:38 + Subject: [PATCH] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. We are replacing with a wider increment. If both OrigInc and IsomorphicInc are NUW/NSW, then we can preserve them on the wider increment; the narrower IsomorphicInc would wrap before the wider OrigInc, so the replacement won't make IsomorphicInc's uses more poisonous. --- .../Utils/ScalarEvolutionExpander.cpp | 28 +-- .../Transforms/IndVarSimplify/iv-poison.ll| 12 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index cf8cea937a6bf..902c4db883769 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -1607,11 +1607,35 @@ void SCEVExpander::replaceCongruentIVInc( const SCEV *TruncExpr = SE.getTruncateOrNoop(SE.getSCEV(OrigInc), IsomorphicInc->getType()); if (OrigInc == IsomorphicInc || TruncExpr != SE.getSCEV(IsomorphicInc) || - !SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc) || - !hoistIVInc(OrigInc, IsomorphicInc, + !SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc)) +return; + + bool BothHaveNUW = false; + bool BothHaveNSW = false; + auto *OBOIncV = dyn_cast(OrigInc); + auto *OBOIsomorphic = dyn_cast(IsomorphicInc); + assert(OrigInc->getType()->getScalarSizeInBits() >= + IsomorphicInc->getType()->getScalarSizeInBits()) && "Should only replace an increment with a wider one."); + if (OBOIncV && OBOIsomorphic) { +BothHaveNUW = +OBOIncV->hasNoUnsignedWrap() && OBOIsomorphic->hasNoUnsignedWrap(); +BothHaveNSW = +OBOIncV->hasNoSignedWrap() && OBOIsomorphic->hasNoSignedWrap(); + } + + if (!hoistIVInc(OrigInc, IsomorphicInc, /*RecomputePoisonFlags*/ true)) return; + // We are replacing with a wider increment. If both OrigInc and IsomorphicInc + // are NUW/NSW, then we can preserve them on the wider increment; the narrower + // IsomorphicInc would wrap before the wider OrigInc, so the replacement won't + // make IsomorphicInc's uses more poisonous. + if (BothHaveNUW || BothHaveNSW) { +OrigInc->setHasNoUnsignedWrap(OBOIncV->hasNoUnsignedWrap() || BothHaveNUW); +OrigInc->setHasNoSignedWrap(OBOIncV->hasNoSignedWrap() || BothHaveNSW); + } + SCEV_DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Eliminated congruent iv.inc: " << *IsomorphicInc << '\n'); diff --git a/llvm/test/Transforms/IndVarSimplify/iv-poison.ll b/llvm/test/Transforms/IndVarSimplify/iv-poison.ll index 38299e0a6b353..383599f614357 100644 --- a/llvm/test/Transforms/IndVarSimplify/iv-poison.ll +++ b/llvm/test/Transforms/IndVarSimplify/iv-poison.ll @@ -64,7 +64,7 @@ define i2 @iv_hoist_both_adds_nsw(i2 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i2 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i2 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i2 [[IV_0]], 1 ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i2 1, [[ARG:%.*]] ; CHECK-NEXT:br i1 [[DOTNOT_NOT]], label [[EXIT:%.*]], label [[LOOP]] ; CHECK: exit: @@ -92,7 +92,7 @@ define i4 @iv_hoist_both_adds_nsw_extra_use(i4 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i4 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i4 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i4 [[IV_0]], 1 ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i4 1, [[ARG:%.*]] @@ -124,7 +124,7 @@ define i4 @iv_hoist_both_adds_nsw_extra_use_incs_reordered(i4 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i4 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i4 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i4 [[IV_0]], 1 ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i4 1, [[ARG:%.*]] @@ -244,7 +244,7 @@ define i2 @iv_hoist_both_adds_nuw(i2 %arg, i2 %start) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i2 [ [[START:%.*]], [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add i2 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i2 [[IV_0]], 1 ; CHECK-NEXT:[[DOTN
[clang] [clang-tools-extra] [llvm] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. (PR #79512)
fhahn wrote: ping :) https://github.com/llvm/llvm-project/pull/79512 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[lld] [libc] [clang-tools-extra] [lldb] [libcxxabi] [clang] [flang] [llvm] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. (PR #79512)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/79512 >From 299a055e271264f918321bf7360ee37c6ede8b26 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Tue, 23 Jan 2024 13:39:38 + Subject: [PATCH] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. We are replacing with a wider increment. If both OrigInc and IsomorphicInc are NUW/NSW, then we can preserve them on the wider increment; the narrower IsomorphicInc would wrap before the wider OrigInc, so the replacement won't make IsomorphicInc's uses more poisonous. --- .../Utils/ScalarEvolutionExpander.cpp | 28 +-- .../Transforms/IndVarSimplify/iv-poison.ll| 12 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index cf8cea937a6bf..902c4db883769 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -1607,11 +1607,35 @@ void SCEVExpander::replaceCongruentIVInc( const SCEV *TruncExpr = SE.getTruncateOrNoop(SE.getSCEV(OrigInc), IsomorphicInc->getType()); if (OrigInc == IsomorphicInc || TruncExpr != SE.getSCEV(IsomorphicInc) || - !SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc) || - !hoistIVInc(OrigInc, IsomorphicInc, + !SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc)) +return; + + bool BothHaveNUW = false; + bool BothHaveNSW = false; + auto *OBOIncV = dyn_cast(OrigInc); + auto *OBOIsomorphic = dyn_cast(IsomorphicInc); + assert(OrigInc->getType()->getScalarSizeInBits() >= + IsomorphicInc->getType()->getScalarSizeInBits()) && "Should only replace an increment with a wider one."); + if (OBOIncV && OBOIsomorphic) { +BothHaveNUW = +OBOIncV->hasNoUnsignedWrap() && OBOIsomorphic->hasNoUnsignedWrap(); +BothHaveNSW = +OBOIncV->hasNoSignedWrap() && OBOIsomorphic->hasNoSignedWrap(); + } + + if (!hoistIVInc(OrigInc, IsomorphicInc, /*RecomputePoisonFlags*/ true)) return; + // We are replacing with a wider increment. If both OrigInc and IsomorphicInc + // are NUW/NSW, then we can preserve them on the wider increment; the narrower + // IsomorphicInc would wrap before the wider OrigInc, so the replacement won't + // make IsomorphicInc's uses more poisonous. + if (BothHaveNUW || BothHaveNSW) { +OrigInc->setHasNoUnsignedWrap(OBOIncV->hasNoUnsignedWrap() || BothHaveNUW); +OrigInc->setHasNoSignedWrap(OBOIncV->hasNoSignedWrap() || BothHaveNSW); + } + SCEV_DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Eliminated congruent iv.inc: " << *IsomorphicInc << '\n'); diff --git a/llvm/test/Transforms/IndVarSimplify/iv-poison.ll b/llvm/test/Transforms/IndVarSimplify/iv-poison.ll index 38299e0a6b353..383599f614357 100644 --- a/llvm/test/Transforms/IndVarSimplify/iv-poison.ll +++ b/llvm/test/Transforms/IndVarSimplify/iv-poison.ll @@ -64,7 +64,7 @@ define i2 @iv_hoist_both_adds_nsw(i2 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i2 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i2 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i2 [[IV_0]], 1 ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i2 1, [[ARG:%.*]] ; CHECK-NEXT:br i1 [[DOTNOT_NOT]], label [[EXIT:%.*]], label [[LOOP]] ; CHECK: exit: @@ -92,7 +92,7 @@ define i4 @iv_hoist_both_adds_nsw_extra_use(i4 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i4 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i4 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i4 [[IV_0]], 1 ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i4 1, [[ARG:%.*]] @@ -124,7 +124,7 @@ define i4 @iv_hoist_both_adds_nsw_extra_use_incs_reordered(i4 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i4 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i4 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i4 [[IV_0]], 1 ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i4 1, [[ARG:%.*]] @@ -244,7 +244,7 @@ define i2 @iv_hoist_both_adds_nuw(i2 %arg, i2 %start) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i2 [ [[START:%.*]], [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add i2 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i2 [[IV_0]], 1 ; CHECK-NEXT:[[DOTN
[lld] [libc] [clang-tools-extra] [lldb] [libcxxabi] [clang] [flang] [llvm] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. (PR #79512)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/79512 >From 299a055e271264f918321bf7360ee37c6ede8b26 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Tue, 23 Jan 2024 13:39:38 + Subject: [PATCH 1/2] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. We are replacing with a wider increment. If both OrigInc and IsomorphicInc are NUW/NSW, then we can preserve them on the wider increment; the narrower IsomorphicInc would wrap before the wider OrigInc, so the replacement won't make IsomorphicInc's uses more poisonous. --- .../Utils/ScalarEvolutionExpander.cpp | 28 +-- .../Transforms/IndVarSimplify/iv-poison.ll| 12 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index cf8cea937a6bf..902c4db883769 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -1607,11 +1607,35 @@ void SCEVExpander::replaceCongruentIVInc( const SCEV *TruncExpr = SE.getTruncateOrNoop(SE.getSCEV(OrigInc), IsomorphicInc->getType()); if (OrigInc == IsomorphicInc || TruncExpr != SE.getSCEV(IsomorphicInc) || - !SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc) || - !hoistIVInc(OrigInc, IsomorphicInc, + !SE.LI.replacementPreservesLCSSAForm(IsomorphicInc, OrigInc)) +return; + + bool BothHaveNUW = false; + bool BothHaveNSW = false; + auto *OBOIncV = dyn_cast(OrigInc); + auto *OBOIsomorphic = dyn_cast(IsomorphicInc); + assert(OrigInc->getType()->getScalarSizeInBits() >= + IsomorphicInc->getType()->getScalarSizeInBits()) && "Should only replace an increment with a wider one."); + if (OBOIncV && OBOIsomorphic) { +BothHaveNUW = +OBOIncV->hasNoUnsignedWrap() && OBOIsomorphic->hasNoUnsignedWrap(); +BothHaveNSW = +OBOIncV->hasNoSignedWrap() && OBOIsomorphic->hasNoSignedWrap(); + } + + if (!hoistIVInc(OrigInc, IsomorphicInc, /*RecomputePoisonFlags*/ true)) return; + // We are replacing with a wider increment. If both OrigInc and IsomorphicInc + // are NUW/NSW, then we can preserve them on the wider increment; the narrower + // IsomorphicInc would wrap before the wider OrigInc, so the replacement won't + // make IsomorphicInc's uses more poisonous. + if (BothHaveNUW || BothHaveNSW) { +OrigInc->setHasNoUnsignedWrap(OBOIncV->hasNoUnsignedWrap() || BothHaveNUW); +OrigInc->setHasNoSignedWrap(OBOIncV->hasNoSignedWrap() || BothHaveNSW); + } + SCEV_DEBUG_WITH_TYPE(DebugType, dbgs() << "INDVARS: Eliminated congruent iv.inc: " << *IsomorphicInc << '\n'); diff --git a/llvm/test/Transforms/IndVarSimplify/iv-poison.ll b/llvm/test/Transforms/IndVarSimplify/iv-poison.ll index 38299e0a6b353..383599f614357 100644 --- a/llvm/test/Transforms/IndVarSimplify/iv-poison.ll +++ b/llvm/test/Transforms/IndVarSimplify/iv-poison.ll @@ -64,7 +64,7 @@ define i2 @iv_hoist_both_adds_nsw(i2 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i2 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i2 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i2 [[IV_0]], 1 ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i2 1, [[ARG:%.*]] ; CHECK-NEXT:br i1 [[DOTNOT_NOT]], label [[EXIT:%.*]], label [[LOOP]] ; CHECK: exit: @@ -92,7 +92,7 @@ define i4 @iv_hoist_both_adds_nsw_extra_use(i4 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i4 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i4 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i4 [[IV_0]], 1 ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i4 1, [[ARG:%.*]] @@ -124,7 +124,7 @@ define i4 @iv_hoist_both_adds_nsw_extra_use_incs_reordered(i4 %arg) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i4 [ 1, [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i4 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw nsw i4 [[IV_0]], 1 ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:call void @use(i4 [[IV_0_NEXT]]) ; CHECK-NEXT:[[DOTNOT_NOT:%.*]] = icmp ult i4 1, [[ARG:%.*]] @@ -244,7 +244,7 @@ define i2 @iv_hoist_both_adds_nuw(i2 %arg, i2 %start) { ; CHECK-NEXT:br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT:[[IV_0:%.*]] = phi i2 [ [[START:%.*]], [[BB:%.*]] ], [ [[IV_0_NEXT:%.*]], [[LOOP]] ] -; CHECK-NEXT:[[IV_0_NEXT]] = add i2 [[IV_0]], 1 +; CHECK-NEXT:[[IV_0_NEXT]] = add nuw i2 [[IV_0]], 1 ; CHECK-NEXT:[[
[flang] [clang] [libcxxabi] [clang-tools-extra] [llvm] [lld] [libc] [lldb] [SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree. (PR #79512)
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/79512 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc] [flang] [clang-tools-extra] [llvm] [SLP] Initial vectorization of non-power-of-2 ops. (PR #77790)
@@ -10654,7 +10703,16 @@ template ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Args &...Params) { assert(E->State == TreeEntry::NeedToGather && "Expected gather node."); unsigned VF = E->getVectorFactor(); - + BVTy ShuffleBuilder(Params...); + // FIXME: Only full gathering is implemented for non-power-of-2 nodes at the + // moment. + if (E->isNonPowOf2Vec()) { +Value *BV = ShuffleBuilder.gather(E->Scalars); +SmallVector Mask(VF, PoisonMaskElem); +std::iota(Mask.begin(), Mask.end(), 0); +ShuffleBuilder.add(BV, Mask); +return ShuffleBuilder.finalize({}); fhahn wrote: Adusted, thanks https://github.com/llvm/llvm-project/pull/77790 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits