aboutsummaryrefslogtreecommitdiff
path: root/test/opt/fold_test.cpp
AgeCommit message (Collapse)Author
2020-05-21Reject folding comparisons with unfoldable types. (#3370)Diego Novillo
Reject folding comparisons with unfoldable types. Fixes #3343 When CCP is evaluating an instruction, it was trying to fold a comparison with 64 bit integers. This was causing a fold failure later since the folder still cannot deal with 64 bit integers.
2020-02-03Implement constant folding for many transcendentals (#3166)Arseny Kapoulkine
* Implement constant folding for many transcendentals This change adds support for folding of sin/cos/tan/asin/acos/atan, exp/log/exp2/log2, sqrt, atan2 and pow. The mechanism allows to use any C function to implement folding in the future; for now I limited the actual additions to the most commonly used intrinsics in the shaders. Unary folder had to be tweaked to work with extended instructions - for extended instructions, constants.size() == 2 and constants[0] == nullptr. This adjustment is similar to the one binary folder already performs. Fixes #1390. * Fix Android build On old versions of Android NDK, we don't get std::exp2/std::log2 because of partial C++11 support. We do get ::exp2, but not ::log2 so we need to emulate that.
2019-12-10Don't crash when folding construct of empty struct (#3092)Steven Perron
* Don't crash when folding construct of empty struct An OpCompositeConstruct of an empty struct will be folded to a constant under normal circumstances. However, if the id limit has been reached and the constant cannot be generated, then other folding rules will be tried. These rules do not handle the case of an empty struct. We add allow it to be handled. Fixes http://crbug/1030194 * Changes based on the review.
2019-12-02Folding: perform add and sub on mismatched integer types (#3084)Steven Perron
Fixes #3040
2019-11-11Update Offset to ConstOffset bitmask if operand is constant. (#3024)Ehsan
Update Offset to ConstOffset bitmask if operand is constant. Fixes #3005
2019-10-28Add two new simplifications. (#2984)greg-lunarg
Implements the following simplifications: (a - b) + b => a (a * b) + (a * c) => a * (b + c) Also adds logic to simplification to handle rules that create new operations that might need simplification, such as the second rule above. Only perform the second simplification if the multiplies have the add as their only use. Otherwise this is a deoptimization of size and performance.
2019-10-17Disallow use of OpCompositeExtract/OpCompositeInsert with no indices (#2980)Jakub Kuderski
2019-09-24Handle extract with no indexes (#2910)Steven Perron
* Handle extract with no indexes It is possible that OpCompositeExtract instructions will not have any indexes. This is not handled well by scalar replacement and instruction folding. Fixes https://crbug.com/1006435 * Fix typo.
2019-09-05Fold Min, Max, and Clamp instructions. (#2836)Steven Perron
Fixes #2830.
2019-09-03Fold Fmix should accept vector operands. (#2826)Steven Perron
Fixes #2819
2019-08-26Refactor instruction folders (#2815)Steven Perron
* 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-07-29Protect against out-of-bounds references when folding OpCompositeExtract (#2774)Diego Novillo
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-05-21Add folding rules for OpQuantizeToF16 (#2614)Steven Perron
Adding the folding rules for OpQuantizeToF16, and fixed some matching tests to check identify new lines.
2019-05-10Do not fold floating point if float controls used (#2569)alan-baker
Fixes #2558 * Mark floating point instructions as non-foldable if any SPV_KHR_float_controls capabilities are present * tests
2019-05-08Add tests for folding 1.4 selects (#2568)alan-baker
Fixes #2554 * Folding rules already handle 1.4 selects so I simply added some tests
2019-03-13Remove duplicates from list of interface IDs in OpEntryPoint instruction (#2449)Steven Perron
* Remove duplicates from list of interface IDs in OpEntryPoint instruction Fixes #2002.
2019-02-20Fix OpDot folding of half float vectors. (#2411)Steven Perron
* Fix OpDot folding of half float vectors. The code that folds OpDot does not handle half floats correctly. After trying to multiple the first components, we get a nullptr because we don't fold half float values. This nullptr gets passed to the code that does the addition, and causes an assert. Fixes #2405.
2019-01-29Remove use of deprecated googletest macro (#2286)Steven Perron
* Remove use of deprecated googletest macro INSTANTIATE_TEST_CASE_P has been deprecated. We need to use INSTANTIATE_TEST_SUITE_P instead. * Remove extra commas from test suites.
2019-01-17Fix overflow when negating INT_MIN. (#2293)Steven Perron
When doing (-INT_MIN) is considered overflow, so we cannot fold it by actually performing the negation. Fixes https://crbug.com/917991
2019-01-16Fix up bit shifts by 32. (#2292)Steven Perron
In C++, a bit shift of the same size as the type is undefined, but it is defined in spir-v. When folding those cases, we have to be careful. We cannot simply do the shift in C++. Fixes https://crbug.com/917697.
2018-12-04Remove undefined behaviour when folding shifts. (#2157)Steven Perron
We currently simulate all shift operations when the two operand are constants. The problem is that if the shift amount is larger than 32, the result is undefined. I'm changing the folder to return 0 if the shift value is too high. That way, we will have defined behaviour. https://crbug.com/910937.
2018-11-14Fix folding of volatile store. (#2048)Steven Perron
When looking for the Volatile mask on a store, the instruction folder accesses an out-of-bounds element. We fix that up. Fixes crbug.com/903530.
2018-10-10Fold divisions by 0. (#1963)Steven Perron
The current implementation in the folder when seeing a division by zero is to assert. In the release build, the compiler will attempt to compute the value, which causes its own problems. The solution I will go with is to fold the division, and just give it the value of 0. The same goes for remainder and mod operations. Fixes #1961.
2018-10-04Make EFFCEE required (#1943)Steven Perron
Fixes #1912. Remove the non-effcee build as EFFCEE is now required.
2018-08-03Cleanup includes. (#1795)dan sinclair
This Cl cleans up the include paths to be relative to the top level directory. Various include-what-you-use fixes have been added.
2018-08-03Rewrite include guards (#1793)dan sinclair
This CL rewrites the include guards to make PRESUBMIT.py include guard check happy.
2018-07-31Transform to combine consecutive access chainsAlan Baker
* Combines OpAccessChain, OpInBoundsAccessChain, OpPtrAccessChain and OpInBoundsPtrAccessChain * New folding rule to fold add with 0 for integers * Converts to a bitcast if the result type does not match the operand type V
2018-07-20Handle undef literal value in vector shuffleAlan Baker
Fixes #1731 * Updated folding rules related to vector shuffle to account for the undef literal value: * FoldVectorShuffleFeedingShuffle * FoldVectorShuffleFeedingExtract * FoldVectorShuffleWithConstants * These rules would commit memory violations due to treating the undef literal value as an accessible composite component
2018-07-16Fix finding constant with particular type. (#1724)Steven Perron
With current implementation, the constant manager does not keep around two constant with the same value but different types when the types hash to the same value. So when you start looking for that constant you will get a constant with the wrong type back. I've made a few changes to the constant manager to fix this. First off, I have changed the map from constant to ids to be an std::multimap. This way a single constant can be mapped to mutiple ids each representing a different type. Then when asking for an id of a constant, we can search all of the ids associated with that constant in order to find the one with the correct type.
2018-07-13Fix infinite loop while folding OpVectorShuffle (#1722)Steven Perron
When folding an OpVectorShuffle where the first operand is defined by an OpVectorShuffle, is unused, and is equal to the second, we end up with an infinite loop. This is because we think we change the instruction, but it does not actually change. So we keep trying to folding the same instruction. This commit fixes up that specific issue. When the operand is unused, we replace it with Null.
2018-07-13Fix size error when folding vector shuffle. (#1721)Steven Perron
When folding a vector shuffle that feeds another vector shuffle causes the size of the first operand to change, when other indices have to be adjusted reletive to the new size.
2018-07-11Add folding rule to merge a vector shuffle feeding another one.Steven Perron
2018-07-11Move tests into namespaces (#1689)dan sinclair
This CL moves the test into namespaces based on their directories.
2018-07-10Cleanup whitespace lint warnings. (#1690)dan sinclair
This CL cleans up the whitespace warnings and enables the check when running 'git cl presubmit --all -uf'.
2018-07-09Move the ir namespace to opt. (#1680)dan sinclair
This CL moves the files in opt/ to consistenly be under the opt:: namespace. This frees up the ir:: namespace so it can be used to make a shared ir represenation.
2018-07-05Move folding routines into a classSteven Perron
The folding routines are currently global functions. They also rely on data in an std::map that holds the folding rules for each opcode. This causes that map to not have a clear owner, and therefore never gets deleted. There has been a request to delete this map. To implement this, we will create a InstructionFolder class that owns the maps. The IRContext will own the InstructionFolder instance. Then the global functions will become public memeber functions of the InstructionFolder. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1659.
2018-06-29Remove stores of undef.Steven Perron
When storing an undef, any value is valid, including the one already in that memory location. So we can avoid the store.
2018-05-25Fold FMix feeding Extract, and use the simplification pass.Steven Perron
We add a new rule to the folding rules to fold an FMix feeding an extract when the alpha value for the element being extracted is either 0 or 1. In those case, we can simple extract from one of the operands to the FMix. With that change the simplification pass completely subsumes the insert-extract elimination pass. So we remove the insert-extract elimination passes and replce them with calls to the simplification pass. In a follow up PR, we should delete the insert-extract elimination pass. Contributes to https://github.com/KhronosGroup/SPIRV-Tools/issues/1570.
2018-05-14Add pass to fold a load feeding an extract.Steven Perron
We have already disabled common uniform elimination because it created sequences of loads an entire uniform object, then we extract just a single element. This caused problems in some drivers, and is just generally slow because it loads more memory than needed. However, there are other way to get into this situation, so I've added a pass that looks specifically for this pattern and removes it when only a portion of the load is used. Fixes #1547.
2018-05-14Fold fclamp feeding compare.Steven Perron
An FClamp instruction forces a values to be within a certain interval. When the upper or lower bound of the FClamp is a constant and the value being compared with is a constant, then in some case we can fold the compared because the entire range is say less than the value. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1549.
2018-05-02Fold divide and multiply by same value.Steven Perron
We want to fold code like (x*y)/x and other permutations of this. Fixes #1531.
2018-04-26Fold OpVectorTimesScalar and OpPhi better.Steven Perron
If one of the operands to an OpVectorTimesScalar instruction is zero, then the result will be the 0 vector. Currently we do not fold the insturction unless both operands are constants. This change fixes that. We also allow folding of OpPhi instructions where the incoming values are either an OpUndef or the OpPhi instruction itself. As with other cases, this can be simplified to the OpUndef.
2018-04-20Constant folding for OpVectorTimesScalarJaebaek Seo
2018-04-17TypoJaebaek Seo
2018-04-17FormatJaebaek Seo
2018-04-17Add more unit testsJaebaek Seo
2018-04-17Add constant folding for FNegateJaebaek Seo
2018-04-10Fold OpDotSteven Perron
Adding three rules to fold OpDot (implemented as two). - When an OpDot has two constants, then fold to the resulting const. - When one of the inputs is the 0 vector, then fold to zero. - When one of the inputs is a single 1 with 0s, then rewrite to an OpCompositeExtract of the appropriate element. This will help find even more folding opportunities. Contributes to #709.
2018-03-07Fixes #1385. Grab correct input to calculate indices.Alan Baker
* Added tests to catch the bug
2018-03-06Fixes #1376. Don't handle half folding gracefully.Alan Baker
* Added early returns to folding rules to prevent half attempts * Added some tests