@@ -64,16 +64,36 @@ SSA is the canonical form expected by much of the optimizer; if allocas can
64
64
not be eliminated by Mem2Reg or SROA, the optimizer is likely to be less
65
65
effective than it could be.
66
66
67
- Avoid loads and stores of large aggregate type
68
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67
+ Avoid creating values of aggregate type
68
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69
+
70
+ Avoid creating values of :ref: `aggregate types <t_aggregate >` (i.e. structs and
71
+ arrays). In particular, avoid loading and storing them, or manipulating them
72
+ with insertvalue and extractvalue instructions. Instead, only load and store
73
+ individual fields of the aggregate.
74
+
75
+ There are some exceptions to this rule:
76
+
77
+ * It is fine to use values of aggregate type in global variable initializers.
78
+ * It is fine to return structs, if this is done to represent the return of
79
+ multiple values in registers.
80
+ * It is fine to work with structs returned by LLVM intrinsics, such as the
81
+ ``with.overflow `` family of intrinsics.
82
+ * It is fine to use aggregate *types * without creating values. For example,
83
+ they are commonly used in ``getelementptr `` instructions or attributes like
84
+ ``sret ``.
85
+
86
+ Avoid loads and stores of non-byte-sized types
87
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88
+
89
+ Avoid loading or storing non-byte-sized types like ``i1 ``. Instead,
90
+ appropriately extend them to the next byte-sized type.
69
91
70
- LLVM currently does not optimize well loads and stores of large :ref: `aggregate
71
- types <t_aggregate>` (i.e. structs and arrays). As an alternative, consider
72
- loading individual fields from memory.
92
+ For example, when working with boolean values, store them by zero-extending
93
+ ``i1 `` to ``i8 `` and load them by loading ``i8 `` and truncating to ``i1 ``.
73
94
74
- Aggregates that are smaller than the largest (performant) load or store
75
- instruction supported by the targeted hardware are well supported. These can
76
- be an effective way to represent collections of small packed fields.
95
+ If you do use loads/stores on non-byte-sized types, make sure that you *always *
96
+ use those types. For example, do not first store ``i8 `` and then load ``i1 ``.
77
97
78
98
Prefer zext over sext when legal
79
99
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 commit comments