Commit Graph

3386 Commits

Author SHA1 Message Date
Steven Perron
32622ba7c6
DCE: clean up the cfg for all functions that were processed. (#4840)
Which functions are processed is determined by which ones are on the
call tree from the entry points before dead code is removed.  So it is
possible that a function is process because it is called from an entry
point, but the CFG is not cleaned up because the call to the function
was removed.

The fix is to process and cleanup every function in the module.  Since
all of the dead functions would have already been removed in an earlier
step of DCE, it should not make a different in compile time.

Fixes #4731
2022-07-05 12:23:32 -04:00
alan-baker
8ec4a0772b
Fix unreachable loop increment (#4836)
* ANGLE builds with -Werror,-Wunreachable-code-loop-increment which had
  a problem with grabbing the first construct in a loop
  * Change the code to just use begin instead
2022-06-30 13:52:50 -04:00
alan-baker
286e9c1187
Use structural dominance to validate cfg (#4832)
* Structural dominance introduced in SPIR-V 1.6 rev2
* Changes the structured cfg validation to use structural dominance
  * structural dominance is based on a cfg where merge and continue
    declarations are counted as graph edges
* Basic blocks now track structural predecessors and structural
  successors
* Add validation for entry into a loop
* Fixed an issue with inlining a single block loop
  * The continue target needs to be moved to the latch block
* Simplify the calculation of structured exits
  * no longer requires block depth
* Update many invalid tests
2022-06-29 23:32:20 -04:00
Steven Perron
91572e769a
Write binary files to stdout in binary on windows. (#4834)
We currently do not set stdout to binary mode when writing a binary
file on Windows.  This cause some extra characters to be written that
mess up the output.  We try to fix that.

Fixes #4793
2022-06-29 15:40:29 -04:00
Mike
0b824324bc
Fix segfault in SpirvTools::Disassemble when printing (#4833)
When the `SPV_BINARY_TO_TEXT_OPTION_PRINT` option is specified, `spvtext` will not be created (see 37d2396cab/source/disassemble.cpp (L117)), and the attempt to dereference into its members (`spvtext->str` and `spvtext->length`) results in segmentation fault.

This is fixed by first checking if `spvtext` is nulll.

Co-authored-by: Steven Perron <stevenperron@google.com>
2022-06-29 12:05:00 -04:00
Steven Perron
66d88508dd
Build struct order only for the section needed when unrolling. (#4830)
We currently build the structured order for all nodes reachable from the
loop header when unrolling a loop.  However, unrolling only needs the
nodes in the loop and possibly the merge node.

To avoid needless computation, I have implemented a search that will
stop at the merge node.

Fixes #4827
2022-06-29 09:53:26 -04:00
Alastair Donaldson
f2dfa53ae5
Avoid unrolling large loops while fuzzing (#4835)
Uses a preprocessor macro to bail out of unrolling loops with large
iteration counts during fuzzing, to reduce the number of
timeouts/memouts that arise.

Related issue: #4728.
2022-06-29 09:12:09 -04:00
Steven Perron
37d2396cab
Fix SplitLoopHeader to handle single block loop (#4829)
The code in `CFG::SplitLoopHeader` assumes the loop header is not the
latch.  This leads to it not being able to find the latch block.  This
has been fixed, and a test added.

Fixes #4527
2022-06-24 12:33:45 -04:00
Steven Perron
3c9fd7577f
Avoid if-conversion if both predecessors are the same (#4826)
If the predecessor blocks are the same, then there is only 1 value for the
OpPhi.  The simplition pass will simplify it, and it causes problems for
if-conversion.  In these cases, if-conversion can just punt.

Fixes #3554.
2022-06-24 15:28:06 +00:00
PENGUINLIONG
c4ed5157dc
Fixed crash unrolling loops with residual iterations (#4820) 2022-06-23 16:01:44 -04:00
Steven Perron
76fe352190
Fail validation when RelaxedPrecision is applied to a type. (#4823)
* Fail validation when RelaxedPrecision is applied to a type.

Fixes #4723
Fixes #4725

* Fixup invalid test
2022-06-21 19:59:01 +00:00
Steven Perron
845d98d468
Do not check if the binary changed if encoding is different (#4824)
There is an assert that verifies that the binary did not change when the
optimizer said that it did not.  However, if the input binary is in big endian
format, the optimizer will encode the optimized binary in little endian.  This
causes the assert to fail.  Since we do not believe that anybody cares about a
big endien formate, we will disable the assert in that case.

Fixes #4722
2022-06-21 19:58:21 +00:00
Steven Perron
4f321f862a
Avoid undefined divide-by-0 (#4821)
The Reciprocal function expects a divide-by-0 to return nan,and then Reciprocal will return 0.

Since the divide-by-0 is actually undefined, we will identify this case early, and return 0.

No new tests are needed because we already tests folding divide-by-0.

Fixes #4715
2022-06-21 11:37:34 -04:00
David Neto
2eff41e707
Remove stray output to stdout from tests (#4816) 2022-06-20 10:57:44 -04:00
manas-kulkarni
fbcb6cf4c8
Ability to fold Constant Vector times Matrix and Matrix times vector instructions (#4818) 2022-06-16 13:54:12 -04:00
Spencer Fricke
bfc611b03e
spirv-val: Label 06807 and 06808 VUID (#4817) 2022-06-15 11:25:16 -04:00
Steven Perron
76ebfb989f
Avoid replacing access chain with OOB access (#4819)
An access chain could have a constant index that is an out of bounds
access.  This is valid spir-v, even if it can cause problems at runtime.
However, it is not valid to have an OpCompositeExtract with an out of
bounds access.  This means we have to stop local-access-chain-convert
from making that change.

Fixes #4605
2022-06-14 13:06:38 -04:00
David Neto
8f7f5024f8
Simplify invocation of snprintf (#4815) 2022-06-10 17:55:45 -04:00
strangewiz
fad68a7551
Fix usage of sprintf. (#4811) 2022-06-08 19:49:46 +00:00
Junda Liu
044ff1aabf
spirv-val: Add support for SPV_AMD_shader_early_and_late_fragment_tests (#4812)
- Update SPIR-V headers.
- Add validator support.
- Add validator tests.
2022-06-08 08:36:32 -04:00
Shahbaz Youssefi
c94501352d
spirv-val: Optimize struct field decoration lookup (#4809)
A std::set is used instead of std::vector, where the elements are
ordered by member index first.  Decorations for fields are now looked up
by going over the range of decorations for the member only, instead of
the whole set.

In an ANGLE test that generates a struct with 4096 members, validation
goes down from ~140ms to ~90ms.  On debug builds, the difference is more
pronounced, going down from ~2.5s to ~600ms.
2022-06-02 11:32:38 -04:00
Diego Novillo
b930e734ea Update CHANGES 2022-05-31 14:48:51 -04:00
Diego Novillo
a138aa4a47 Roll external/spirv-headers/ b765c355f..5a1218669 (1 commit)
b765c355f4...5a12186692

$ git log b765c355f..5a1218669 --date=short --no-merges --format='%ad %ae %s'
2022-05-20 waprave Implemented Beef language header generation

Created with:
  roll-dep external/spirv-headers
2022-05-31 14:40:22 -04:00
Diego Novillo
13e296b316 Roll external/re2/ 0c5616df9..5723bb895 (6 commits)
0c5616df9c...5723bb8950

$ git log 0c5616df9..5723bb895 --date=short --no-merges --format='%ad %ae %s'
2022-05-09 junyer Add GCC 12 to the build matrix.
2022-04-11 junyer Switch to `cxx_std_11` as per best current practice.
2022-04-08 junyer Mea culpa. The `DCHECK` needs to be an `if`.
2022-04-08 junyer Use `size_t` to stop MSVC griping about conversion.
2022-04-08 junyer `#include` `<cmath>` instead of `<math.h>`.
2022-04-06 junyer Prune `PrefilterTree` edges instead of nodes.

Created with:
  roll-dep external/re2
2022-05-31 14:40:20 -04:00
Diego Novillo
e97dfb6626 Roll external/googletest/ 25dcdc7e8..548b13dc3 (38 commits)
25dcdc7e8b...548b13dc3c

$ git log 25dcdc7e8..548b13dc3 --date=short --no-merges --format='%ad %ae %s'
2022-05-31 absl-team Fix internal files
2022-05-30 jacobsa gmock-spec-builders: remove the name for an unused parameter.
2022-05-27 jacobsa gmock-spec-builders: add support for non-moveable types.
2022-05-27 elixir Clarify that `this->` is needed to access members of type-parameterized tests.
2022-05-27 jacobsa gmock-actions: properly support non-moveable results in `is_callable_r`.
2022-05-26 jacobsa gmock-spec-builders: move a method to the header.
2022-05-25 absl-team Update GoogleTest documentation's spelling of "GoogleTest".
2022-05-24 absl-team Clarify the pitfalls of EXPECT_THAT and highlight it's best practices
2022-05-17 dinor gmock-internal-utils.cc: Avoid implicit conversion from int to char Fixes #3832
2022-05-12 jacobsa gmock-actions: add support for move-only values to Return.
2022-05-12 absl-team Add clarifying comments about when to use EXPECT_NONFATAL_FAILURE vs. EXPECT_FATAL_FAILURE.
2022-05-11 jacobsa gmock-actions: provide a const reference when converting in ReturnAction.
2022-05-10 absl-team Do a consistent way of searching for a temporary directory.
2022-05-10 jacobsa gmock-actions: simplify Return and add better documentation.
2022-05-10 jacobsa gmock-actions: make OnceAction public.
2022-05-10 absl-team Fixup some missing overrides in googletest.
2022-05-03 absl-team Fix example of DescribeMatcher to properly support negation.
2022-05-02 absl-team Use TEST_TMPDIR on MacOS as well if available.
2022-05-02 jacobsa gmock-actions: remove a no-longer-necessary friend declaration.
2022-05-02 jacobsa gmock-actions: support ByMove in a specialization of ReturnAction.
2022-04-30 ayush854032 Fix typo in the test name of `NormalizeTest`
2022-04-28 absl-team Rewrite "Testing a Certain Property of an Object" as "Defining a Custom Matcher Class", and fix the code examples.
2022-04-27 jacobsa gmock-actions: improve comments and tests for the implicit cast in Return.
2022-04-26 jacobsa Support move-only and &&-qualified actions in WithArgs.
2022-04-26 dmauro Use RE2 for the regex implementation when building with Bazel and using Abseil
2022-04-26 absl-team Generalize gmock-matchers_test to handle is_gtest_matcher-style matchers, too.
2022-04-26 jacobsa Support move-only and &&-qualified actions in DoAll.
2022-04-22 dmauro Remove the legacy internal GTEST_DISALLOW_* macros
2022-04-21 dmauro Eliminate the legacy GTEST_COMPILE_ASSERT_ macro
2022-04-20 mhommey Always initialize fields in MatcherBase constructors
2022-04-13 jacobsa Document two surprises in `DoAllAction::NonFinalType`.
2022-04-13 absl-team Replace infinite recursion call (intentionally invoking undefined behavior to indicate unreachability) with explicit unreachability marker.
2022-04-08 absl-team Add support for move-only and &&-qualified actions in WillOnce.
2022-04-06 52797899+MR-A0101 Removing commas.
2022-04-06 dmauro Clarify what live-at-head actually means
2022-04-04 absl-team Trying to make it more clear: this is probably not about mock classes, but about mocked classes
2022-04-04 absl-team gmock: improve SFINAE for actions involving arguments.
2022-04-04 absl-team Use ResultOf()'s result_description when explaining match result.

Created with:
  roll-dep external/googletest
2022-05-31 14:40:17 -04:00
Nicolas Capens
130a05d2e3
Fold multiply and subtraction into FMA with negation (#4808)
This change adds a folding rule which transforms x * y - a and a - x * y
into FMA(x, y, -a) and FMA(-x, y, a), respectively.

While the SPIR-V instruction count remains the same, target instruction
sets typically feature FMA instruction variants that can negate an
operand. Also this transformation may unlock further optimizations which
eliminate the negation.

(Google bug: b/226145988)
2022-05-31 12:03:56 -04:00
Spencer Fricke
82d91083cb
spirv-val: Add PerVertexKHR (#4807) 2022-05-26 13:11:05 -04:00
Steven Perron
088cb1a5c8
Add more folding for composite instructions (#4802)
* Add move folding for composite instructions

Fold chains of insert into construct

If a chain of OpCompositeInsert instruction write to every element of a
composite object, then we can replace it with an OpCompositeConstruct.

Fold a construct fed by extracts to a single extract

We already fold an OpCompositeConstruct when it is simlpy reconstructing
an object that was decomposed by a series of OpCompositeExtract
instructions.  However, we do not do that if that object is an element
of a larger object.

I have updated the rule, so that if the original object is a an element
of a larger object, then the OpCompositeConstruct is replaced with a
single OpCompositeExtract from the larger object.

Fixes #4371.
2022-05-26 10:29:02 -04:00
stu-s
c267127846
Add SPV_KHR_fragment_shader_barycentric support (#4805)
* Add SPV_KHR_fragment_shader_barycentric support
2022-05-25 09:20:39 -04:00
Ryan Harrison
98340ec500
Add warning about spurious 'git cl upload' messages (#4800)
Fixes #4186
2022-05-11 15:17:21 -04:00
Steven Perron
f74b85853c
Handle 64-bit integers in local access chain convert (#4798)
* Handle 64-bit integers in local access chain convert

The local access chain convert pass does on run on module that have
64-bit integers, even if they have nothing to to with access chains.
This is very limiting because other passes rely on the access chains
being removed. So this commit will add this functionality to the pass.
2022-05-10 17:02:14 +00:00
Daniele Vettorel
f7a6e3b9d5
Handle chains of OpAccessChain in replacing variable index access for flattened resources. (#4797) 2022-05-10 11:41:43 -04:00
Jaebaek Seo
ad3514b732
spirv-opt: add pass for interface variable scalar replacement (#4779)
Replace shader's stage variables whose types are array or matrix
with scalars/vectors.
For example,
```
Before:
  %foo = OpVariable %_ptr_Output__arr_v2float_uint_4 Output
After:
  %foo = OpVariable %_ptr_Output_v2float Output
  %foo_0 = OpVariable %_ptr_Output_v2float Output
  %foo_1 = OpVariable %_ptr_Output_v2float Output
  %foo_2 = OpVariable %_ptr_Output_v2float Output
```
2022-05-09 14:04:52 -04:00
Rayan Hatout
ffc8f2d455
Remove deprecated flags from spirv-opt help message (#4788)
* Remove deprecated `--decompose-initialized-variables` from spirv-opt help message

* Remove deprecated --strip-atomic-counter-memory flag from spirv-opt help message
2022-05-06 17:10:14 +00:00
JiaoluAMD
c11ea09652
spirv-opt : Add FixFuncCallArgumentsPass (#4775)
spirv validation require OpFunctionCall with memory object, usually this
is non issue as all the functions are inlined.
This pass deal with some case for
DontInline function. accesschain input operand would be replaced new
created variable
2022-05-06 10:39:26 -04:00
Daniel Koch
9e377b0f97
spirv-val: Add CullMaskKHR support (#4792)
Co-authored-by: sfricke-samsung <s.fricke@samsung.com>
2022-05-06 07:32:56 -04:00
Kévin Petit
7014be600c
Add support for SPV_KHR_subgroup_rotate (#4786)
- Add assembler/disassembler support
- Add validator support

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
Change-Id: Iffcedd5d5e636a0e128a5906ffe634dd85727de1
2022-05-05 08:58:05 -04:00
JiaoluAMD
2c7fb9707b
Handle dontinline function in spread-volatile-semantics (#4776)
Handle function calls in spread-volatile-semantics
2022-05-04 10:52:58 -04:00
Steven Perron
58dc37ea6a
Add SpvBuiltInCullMaskKHR to a switch (#4790)
Add SpvBuiltInCullMaskKHR to a switch so spirv-tools can compile with
the latest headers.
2022-05-03 14:39:51 -04:00
Steven Perron
1295dca8e2
Reapply "Add folding rule to generate Fma instructions (#4783)" (#4789)
This reverts commit 671f6e633f.

PR #4783 was reverted because it caused OpenCL CTS failures for clvk.
The was in clspv, which was not adding the no contract decoration when
it was required.  This has been fixed in
https://github.com/google/clspv/pull/845.  We can now reapply #4783.
2022-05-03 10:20:23 -04:00
Karol Herbst
edaf51038b
linker: Recalculate interface variables (#4784)
* linker: Recalculate interface variables

By resolving extern symbols Entry Points might access variables they
hadn't declared before.

* test/linker: add test to verify linked spir-vs importing functions validate

Without the fix Validate will complain about:

"ERROR: 9: Interface variable id <5> is used by entry point 'bar' id <1>, but is not listed as an interface\n  %5 = OpVariable %_ptr_Input_v3uint Input\n"
2022-05-03 13:23:02 +00:00
sindney
46492aa45a
spirv-opt: skips if_conversion when dontflatten is set (#4770) 2022-04-28 19:26:02 +00:00
Daniele Vettorel
671f6e633f
Revert "Add folding rule to generate Fma instructions (#4783)" (#4785)
This reverts commit 2b2b0282af.
2022-04-20 10:55:20 -04:00
Steven Perron
2b2b0282af
Add folding rule to generate Fma instructions (#4783)
Adding Fma instruction can speed up the code.  This was requested by
swiftshader, so they do not have to do this analysis themselves.  It can
also help reduce the code size, and the work the ICD compilers have to
do.
2022-04-19 11:25:07 -04:00
Chad Versace
cb96abbf7a
Fix CMake for librt (#4773)
In the installed file
/usr/lib64/cmake/SPIRV-Tools/SPIRV-ToolsTarget.cmake, occurences of
librt in the INTERFACE_LINK_LIBRARIES property are incorrect.  The
property contains the absolute path to librt. In most situations, this
produces no problem. But when building in a sysroot, which is commonly
done when cross-compiling, the absolute path breaks dependent projects.

For example, when building spirv-tools using the Chrome OS SDK, and
targeting the board 'volteer', where the build sysroot is
'/build/volteer', the file includes this line
    INTERFACE_LINK_LIBRARIES "/build/volteer/usr/lib64/librt.so"
when it should instead say
    INTERFACE_LINK_LIBRARIES "rt"

The CMake documentation agrees [1]:
    Note that it is not advisable to populate the
    INTERFACE_LINK_LIBRARIES of a target with absolute paths to
    dependencies. That would hard-code into installed packages the
    library file paths for dependencies as found on the machine the
    package was made on.

[1] https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_LINK_LIBRARIES.html
2022-04-14 09:04:12 -04:00
Steven Perron
898ba64d24
Use cmake 3.23 on Windows. (#4782) 2022-04-13 13:56:19 -04:00
Steven Perron
92c17edde7
Don't try to unroll loop with step count 0. (#4769)
These loop are infinite loop, so there is no reason to unroll the loop.
Fixes #4711.
2022-04-11 10:21:15 -04:00
Natalie Chouinard
c1bb0b9415 Start SPIRV-Tools v2022.3-dev 2022-04-07 19:24:58 +00:00
Natalie Chouinard
7826e1941e Finalize SPIRV-Tools v2022.2 2022-04-07 19:21:52 +00:00
Natalie Chouinard
67fdf94097 Update CHANGES 2022-04-07 14:48:13 +00:00