Commit Graph

490 Commits

Author SHA1 Message Date
Steven Perron
73422a0a5e
Check feature mgr in context consistency check (#2818)
We add a check that the feature manager is correcter after each pass.

This resulted in a couple failing tests cases.  Those are fixed.

Part of #2814
2019-08-28 11:49:16 -04:00
Steven Perron
15fc19d091
Refactor instruction folders (#2815)
* Refactor instruction folders

We want to refactor the instruction folder to allow different sets of
rules to be added to the instruction folder.  We might want different
sets of rules in different circumstances.

We also need a way to add rules for extended instructions.  Changes are
made to the FoldingRules class and ConstFoldingRules class to enable
that.

We added tests to check that we can fold extended instructions using the
new framework.

At the same time, I noticed that there were two tests that did not tests
what they were suppose to.  They could not be easily salvaged. #2813 was
opened to track adding the new tests.
2019-08-26 18:54:11 -04:00
Steven Perron
b00ef0d26e
Handle Id overflow in private-to-local (#2807)
We need to handle id overflow in the private to local pass.

Fixes https://crbug.com/962295
2019-08-22 09:14:48 -04:00
Steven Perron
aef8f92b2b
Even more id overflow in sroa (#2806)
Now we need to handle id overflow when we overflow while replacing uses of the variable.  While looking at this code, I noticed an error in the way we handle access chains that cannot be replaced because of overflow.  Name it will make some change, and then give up by returning SuccessWithoutChange.  But it was changed.

This is fixed up by returning Failure if we notice the error at the time of rewriting the users.  This is for both id overflow or out-of-bounds accesses.

Code is added to "CheckUses" to remove variables that have out-of-bounds accesses from the candidate list, so we don't even try to rewrite its uses.

Fixes https://crbug.com/995032
2019-08-21 13:12:42 -04:00
Steven Perron
c5d1dab99e
Add name for variables in desc sroa (#2805)
Fixes #2802.
2019-08-21 10:55:02 -04:00
Steven Perron
bc62722b80
Handle overflow in wrap-opkill (#2801)
Fixes https://crbug/994203
2019-08-18 19:00:18 -04:00
Steven Perron
9cd07272a6
More handle overflow in sroa (#2800)
If we run out of ids when creating a new variable, sroa does not recognize
the error, and continues doing work.  This leads to segmentation faults.

Fixes https://crbug/969655
2019-08-16 13:15:17 -04:00
greg-lunarg
06407250a1 Instrument: Add support for Buffer Device Address extension (#2792) 2019-08-16 09:18:34 -04:00
Steven Perron
60043edfa1
Replace OpKill With function call. (#2790)
We are no able to inline OpKill instructions into a continue construct.
See #2433.  However, we have to be able to inline to correctly do
legalization.  This commit creates a pass that will wrap OpKill
instructions into a function of its own.  That way we are able to inline
the rest of the code.

The follow up to this will be to not inline any function that contains
an OpKill.

Fixes #2726
2019-08-14 09:27:12 -04:00
Steven Perron
f701237f2d
Remove useless semi-colons (#2789)
Later versions of clang seem to pick up more useless semi-colons.  I've removed them.
2019-08-12 08:52:39 -04:00
greg-lunarg
95386f9e45 Instrument: Fix version 2 output record write for tess eval shaders. (#2782)
Fix output record write for tess eval shaders.

Also change command line for bindless instrumentation to use use
output record version 2.
2019-08-09 08:22:41 -04:00
Steven Perron
4b64beb1ae
Add descriptor array scalar replacement (#2742)
Creates a pass that will replace a descriptor array with individual variables.  See #2740 for details.

Fixes #2740.
2019-08-08 10:53:19 -04:00
greg-lunarg
29af42df12 Add SPV_EXT_physical_storage_buffer to opt whitelists (#2779)
This also fixes ADCE to not remove possibly needed OpTypeForwardPointer.
The bug, its fix and the corresponding test have a circular dependency
with the extension, so they are packaged together.
2019-08-08 09:45:59 -04:00
Steven Perron
b029d3697e
Handle RelaxedPrecision in SROA (#2788)
If a member of a struct has a relaxed precision, sroa will not split the
struct.  This means we do not get all cases.  This commit handles these
cases.  The other part is that the decoration needs to be passed on to
the new variables.

Fixes #2786
2019-08-07 12:17:26 -04:00
alan-baker
3726b500b1
Treat access chain indexes as signed in SROA (#2776)
Fixes #2768

* In scalar replacement, interpret access chain indexes as signed counts
* Use Constant::GetSignExtendedValue and Constant::GetZeroExtendedValue
where appropriate
* new tests
2019-07-31 15:39:33 -04:00
David Neto
31590104ec
Add pass to inject code for robust-buffer-access semantics (#2771)
spirv-opt: Add --graphics-robust-access

Clamps access chain indices so they are always
in bounds.

Assumes:
- Logical addressing mode
- No runtime-array-descriptor-indexing
- No variable pointers

Adds stub code for clamping coordinate and samples
for OpImageTexelPointer.

Adds SinglePassRunAndFail optimizer test fixture.

Android.mk: add source/opt/graphics_robust_access_pass.cpp

Adds Constant::GetSignExtendedValue, Constant::GetZeroExtendedValue
2019-07-30 19:52:46 -04:00
David Neto
7621034aae
Add opt test fixture method SinglePassRunAndFail (#2770)
Checks for failure status code and matches against
the expected error message.
2019-07-30 10:38:46 -04:00
Diego Novillo
49797609b7
Protect against out-of-bounds references when folding OpCompositeExtract (#2774)
This fixes #2608.

The original test case had an out-of-bounds reference that ended up
folding into OpCompositeExtract that was indexing right outside the
constant composite.

The returned constant would then cause a segfault during constant
propagation.
2019-07-29 13:27:40 -07:00
alan-baker
7fd2365b06
Don't move debug or decorations when folding (#2772)
Fixes #2764

* Don't replace all uses when simplifying instructions, instead only
update non-debug, non-decoration uses
  * added a test
* Add a new version of RAUW that takes a predicate to decide whether to
replace the use or not
  * used in simplification pass
2019-07-29 16:20:43 -04:00
Diego Novillo
9559cdbdf0
Fix #2609 - Handle out-of-bounds scalar replacements. (#2767)
* Fix #2609 - Handle out-of-bounds scalar replacements.

When SROA tries to do a replacement for an OpAccessChain that is exactly
one element out of bounds, the code was trying to access its internal
array of replacements and segfaulting.

This protects the code from doing this, and it additionally fixes the
way SROA works by not returning failure when it refuses to do a
replacement.  Instead of failing the optimization pass, SROA will now
simply refuse to do the replacement and keep going.

Additionally, this patch fixes the SROA logic to now return a proper status so we can
correctly state that the pass made no changes to the IR if it only found
invalid references.
2019-07-26 12:33:40 -04:00
Steven Perron
bb0e2f65bb
Fix check for unreachable blocks in merge-return (#2762)
Merge return expects unreachable merge block to look a certain way, and
unreachable continue blocks to look a certain way.  What if an
unreachable block is both a merge and a continue?  The continue is
suppose to take precedent, but merge-return implements it with the merge
taking precedent.  This change flips that around.

Fixes #2746
2019-07-25 09:34:18 -04:00
Steven Perron
c7fcb8c3b9
Process OpDecorateId in ADCE (#2761)
* Process OpDecorateId in ADCE

When there is an OpDecorateId instruction that is live,
the ids that is references must be kept live.  This change
adds them to the worklist.

I've also updated a validator check to allow OpDecorateId
to be able to apply to decoration groups.

Fixes #1759.

* Remove dead code.
2019-07-24 14:43:49 -04:00
Steven Perron
fb83b6fbb5
Record correct dominators in merge return (#2760)
In merge return, we need to know the original dominator for a block in order to
traverse code from the original dominator to the new dominator and add
appropriate Phi nodes.  The current code gets this wrong because the dominator
tree is build as needed.  The first time we get the immediate dominator for a
function we just built the dominator tree and it takes into account that a
block has been split.  The second time it does not.

This inconsistency needs to be fixed.  We do that by recording the original
dominator for all blocks at the start of the pass.

If we were to record just the basic block, that could change if the block is
split.  We want to traverse the code in the body of the original dominator,
whatever block it ends up in.  To make this easy to track, we not save the
terminator instruction to represent the original dominator.

Fixes #2745
2019-07-24 13:56:54 -04:00
Steven Perron
c9190a54da
SSA rewriter: Don't use trivial phis (#2757)
When a phi candidate is marked as trivial, we are suppose to update all
of its uses to the reference the value that it is being folded to.
However, the code updates the uses misses `defs_at_block_`.  So at a
later time, the id for the trivial phi can reemerge.

Fixes #2744
2019-07-23 17:59:30 -04:00
greg-lunarg
3855447d93 Bindless Instrument: Make init check depend solely on input_init_enabled (#2753)
* Bindless Instrument: Make init check depend solely on input_init_enabled

Previously was dependent on presense of descriptor_indexing extension
in SPIR-V, but this missed some cases. Tests updated to refect this new
policy.

* Fix format.
2019-07-22 13:51:39 -04:00
Steven Perron
aa9e8f5380
Revert "Do not inline OpKill Instructions (#2713)" (#2749)
This reverts commit fe7cc9c612.
2019-07-17 14:59:05 -04:00
Steven Perron
230c9e4371
Fix bug in merge return (#2734)
* Fix bug in merge return

The merge return pass seems to assume that the only new edges in the cfg
are from return block to merge blocks.  However, it is possible that a
merge block branches to a merge block when it did not before.

This change add a new variable to track all of the new edges.  It also
renames some other variables and cleans us the code to make it a bit
easier to read.

Fixes #2702.
2019-07-16 09:11:22 -04:00
Jason Macnak
1fedf72e50 Allow ray tracing shaders in inst bindle check pass. (#2733)
Adds the ray tracing stages (ray gen, intersection, any hit, closest hit,
miss, and callable) to the allowed stages in pass instrumentation and add
debug records for these stages to output the global launch id.

More information for ray tracing shaders:
- https://github.com/KhronosGroup/GLSL/blob/master/extensions/nv/GLSL_NV_ray_tracing.txt
2019-07-15 16:24:42 -04:00
greg-lunarg
92c41ff1e7 Remove Common Uniform Elimination Pass (#2731)
Remove Common Uniform Elimination Pass

Fixes #2520.
2019-07-12 11:02:10 -04:00
Steven Perron
5ce8cf781f
Change the order branches are simplified in dead branch elim (#2728)
Dead branch elimination needs to know about the constructs that a block is contained it when determining what to do with its merge instruction.  We currently fold branches in block as we see them, which is parent constructs before their children.  This causes the struct cfg analysis to crash because it tries to get the parent construct for a block after the parent has been folded.

This can be fixed by folding the branch of the children before the parents.

Fixes #2667.
2019-07-10 14:59:44 -04:00
Thomas Roughton
cd153db8ed Add —preserve-bindings and —preserve-spec-constants (#2693)
Add optimizer options to for preservation of spec constants and variable with
binding decorations.  They are to be preserved even if they are unused.
2019-07-10 14:12:19 -04:00
Steven Perron
86e45efe15
Handle decorations better in some optimizations (#2716)
There are a couple spots where we are not looking at decorations when we should.

1. Value numbering is suppose to assign a different value number to ids if they have different decorations.  However that is not being done for OpCopyObject and OpPhi.

1. Instruction simplification is propagating OpCopyObject instruction without checking for decorations.  It should only do that if no decorations are being lost.

Add a new function to the decoration manager to check if the decorations of one id are a subset of the decorations of another.

Fixes #2715.
2019-07-10 11:37:16 -04:00
Steven Perron
37e8f79946
Perform merge return with single return in loop. (#2714)
Inlining does not inline functions that have a single return that is in a loop.  This is because the return cannot be replaced by a branch outside of the loop easily.  Merge return knows how to rewrite the function so the return is replaced by a branch.

Fixes #2038.
2019-07-04 14:14:49 -04:00
Steven Perron
fe7cc9c612
Do not inline OpKill Instructions (#2713)
It is illegal to inline an OpKill instruction into a continue construct because the continue header will no longer dominate the backedge.

This commit adds a check for this, and does not inline.

If we still want to be able to inline a function that contains an OpKill, we can add a new pass that will wrap OpKill instructions into its own function with just the single instruction.

I do not believe that this is a common case right now, so I will not do that yet.

Fixes #2433.
2019-07-04 12:08:23 -04:00
Jason Macnak
e6e3e2ccc6 Update type for loaded builtin GlobalInvocationID in pass instrumentation (#2705)
When working on descriptor indexing validation for compute shaders, the
gl_GlobalInvocationID builtin was being loaded as uint which would cause
compute shaders instrumented by the bindless check pass to have:

%83 = OpLoad %uint %gl_GlobalInvocationID
%84 = OpCompositeExtract %uint %83 0
%85 = OpCompositeExtract %uint %83 1
%86 = OpCompositeExtract %uint %83 2

which results in validation failures:

error: line 127: Reached non-composite type while indexes still remain
to be traversed.
%84 = OpCompositeExtract %uint %83 0

for trying to extract a uint from a uint.
2019-06-28 09:46:16 -04:00
alan-baker
2090d7a2d2
Handle volatile memory semantics in upgrade (#2674)
* If an atomic is decorated with volatile add the volatile bit to its
memory semantics
2019-06-17 16:01:37 -04:00
alan-baker
59983a6010 Validate variable initializer type (#2668)
Fixes #249

* The pointed to type of Result Type must match the initializer type
* Had to update some opt tests to be valid
2019-06-15 00:34:18 -04:00
greg-lunarg
43fb2403a6 Instrument: Fix code for version 2 output format. (#2655)
Correct record size. Also bring version 2 tests up to version 1
equivalence.
2019-06-06 11:35:34 -04:00
David Neto
d01a3c3b4b
Optimizer: Handle array type with OpSpecConstantOp length (#2652)
When it's an OpConstant or OpSpecConstant, then the literal
values are compared.  If the OpSpecConstant also has a SpecId
decoration, then that's also compared.

Otherwise, it's an OpSpecConstantOp and we only compare the
ID of the OpSpecConstantOp instruction itself.

Fixes #2649
2019-06-05 16:35:50 -04:00
Pierre Moreau
e7866de4b1 Linker: Better type comparison for OpTypeArray and OpTypeForwardPointer (#2580)
* Types: Avoid comparing IDs for in Type::IsSameImpl

When linking, we end up with duplicate types for imported and exported
types, that needs to be removed. The current code would reject valid
import/export pairs of symbols due to IDs mismatch, even if the types or
constants behind those ID were the same.

Enabled remaining type_match_test

Fixes #2442
2019-05-29 16:12:02 -04:00
Ryan Harrison
0125b28ed4
Add compact ids to WebGPU <-> Vulkan transformations (#2639)
Fixes #2634
2019-05-29 12:58:37 -07:00
greg-lunarg
3d62cb8148 Instrument: Add version 2 of record formats (#2630)
New version has additional word in stage-specific section. Also
some changes in content for tesselation and compute shaders. Either
version can be invoked at pass creation. This is done to ease integration
and updating of validation layers. Version 1 is deprecated and eventually
will go away.

Also sneaking in fix to version 1 compute shaders.
2019-05-29 15:08:21 -04:00
Steven Perron
6c7db9c630
Handle nested breaks from switches. (#2624)
* Handle nested breaks from switches.

There was a recent decision made to allow branches to the merge node of
a switch even if the switch is not the first enclosing construct.  They
can be generated by glslang from break statements in switches.

Dead branch elimination seems to be the only optimization that will
break because of this change, so I will update that optimizations.

The change made are:

- Track switches in structured cfg analysis.
- In Dead branch elimination:
  - Look for nested breaks that will require a switch instruction.
  - Rewrite, but don't delete, switchs that are required even if it
    could be replaced by an unconditional branch.
  - When looking for the first break, consider the merge of a switch
    as well.

See #2612.

* Fix variable names and comments.

* Add tests for the struct cfg analysis and switches.

* Fix typos in comments.
2019-05-27 16:28:14 -04:00
Steven Perron
d9c00e1d2d Add folding rules for OpQuantizeToF16 (#2614)
Adding the folding rules for OpQuantizeToF16, and fixed some matching
tests to check identify new lines.
2019-05-21 23:15:01 -07:00
Steven Perron
0982f0212e
Using the instruction folder to fold OpSpecConstantOp (#2598)
In order to try to reduce code duplication and to be able
to fold more cases, we want to use the instruction folder
when folding an OpSpecConstantOp with constant operands.

A couple other changes are need to make this work.  First
GetDefiningInstruction| in the constant manager is able
to handle |type_id| being logically equivalent to another
type, so we updated the interface, and removed the assert.

Some tests were also updated because we not generate
better code because constants are not duplicated as much
as before.

No need for new tests.  The functionality of the instruction folder is
already tested.  There are tests check that the instruction folder is
being used correctly for OpCompositeExtract and OpVectorShuffle in the
existing test cases.

Fixes #2585.
2019-05-21 12:45:00 -04:00
greg-lunarg
9dfd4b8358 Bindless Validation: Instrument descriptor-based loads and stores (#2583)
Essentially, support UBOs and SSBOs, scalar and array (sized and unsized).
2019-05-15 19:43:23 -04:00
alan-baker
fc7b5d8c6a Mem model spv 1.4 (#2565)
* Update memory model support for SPIR-V 1.4

Fixes #2552

* Upgrade memory model now supports two memory access operands for
OpCopyMemory*
  * in all cases the pass will first generate two operands by either
  adding them or copying
  * updates accounts for multiple operands
  * tests
2019-05-15 19:06:37 -04:00
Steven Perron
84503583c6
Handle id overflow in sroa better. (#2582)
There is a case where sroa is not handling id overflow gracefully.  It
is handled and an error message is output when the ids overflow.

Fixes https://crbug.com/961030.
2019-05-15 09:29:28 -04:00
alan-baker
2947e88f79 Update instrumentation passes to handle 1.4 interfaces (#2573)
Fixes #2556

Added variables get added to entry point interfaces
Add to input buffer too
2019-05-10 11:08:28 -04:00
alan-baker
87c4ef8a9c
Do not fold floating point if float controls used (#2569)
Fixes #2558

* Mark floating point instructions as non-foldable if any
SPV_KHR_float_controls capabilities are present
  * tests
2019-05-10 11:03:22 -04:00