Ordering of patterns should not be of importance anymore since the predicates used are mutually exclusive now.
Details
Diff Detail
Event Timeline
We could, in addition to the new predicates, reorder the patterns which use them resulting in exposure of the underlying dependence of the order the patterns are laid out.
I stuck with Val & 0xfff instead of suggested isUInt<16>(Val) since it seems that it behaves differently.
Some quick inlined comments.
Can you provide a test case where you check the various edge values and use a combination of CHECK and CHECK-NOT to assert that the ISel is picking the expected instructions?
E.g.
define i32 @ret_zero() { CHECK-MIPS: addiu $2, $zero, 0 CHECK-MIPS-NOT: lui CHECK-MIPS-NOT: ori CHECK-MIPS-NOT: li16 ret i32 0 }
The goal of the test case is to document what's "canonical" for us in terms of constant materialisation or at least the current behaviour.
lib/Target/Mips/MicroMipsInstrInfo.td | ||
---|---|---|
1009–1015 | Use AdditionalPredicates with a scope to cover both the def and multidef. | |
1018–1023 | Delete these patterns, they are covered by the MaterializeImms multiclass and the explict pattern for LI16_MM above. | |
lib/Target/Mips/MipsInstrInfo.td | ||
2736–2744 | Your suggestion for reordering the predicates is a good one, can you invert the order and add a comment saying why they are in an unusual order? |
LGTM with inline nits addressed.
lib/Target/Mips/MipsInstrInfo.td | ||
---|---|---|
1836–1851 | These should go in the block of other leaf patterns starting at 1155. | |
1839–1840 | You can return the result of isUInt<16>(ZVal) && !isInt<16> directly, as isUInt<16> already tests return static_cast<int16_t>(x) == x; See include/llvm/Support/MathExtras.h | |
test/CodeGen/Mips/constMaterialization.ll | ||
3 ↗ | (On Diff #118789) | Add a comment here explaining that this test documents/tests the patterns used for constant materialization. |
7 ↗ | (On Diff #118789) | This check line needs to be indented to the same level as the check lines below. This applies to the rest of the functions in this test. |
35 ↗ | (On Diff #118789) | This should be ALL. |
75 ↗ | (On Diff #118789) | Stray whitespace here and in the rest of the functions at the same location. |
90 ↗ | (On Diff #118789) | Check that a negative number that doesn't have the lower 16 bits is synthesized with a single lui. |
Use AdditionalPredicates with a scope to cover both the def and multidef.