- if (shrink_dest_to_read_mask(&instr->dest.ssa)) {
- instr->num_components = instr->dest.ssa.num_components;
- return true;
+ if (nir_intrinsic_infos[instr->intrinsic].has_dest) {
+ /* loads: Trim the dest to the used channels */
+
+ if (shrink_dest_to_read_mask(&instr->dest.ssa)) {
+ instr->num_components = instr->dest.ssa.num_components;
+ return true;
+ }
+ } else {
+ /* Stores: trim the num_components stored according to the write
+ * mask.
+ */
+ unsigned write_mask = nir_intrinsic_write_mask(instr);
+ unsigned last_bit = util_last_bit(write_mask);
+ if (last_bit < instr->num_components && instr->src[0].is_ssa) {
+ nir_ssa_def *def = nir_channels(b, instr->src[0].ssa,
+ BITSET_MASK(last_bit));
+ nir_instr_rewrite_src(&instr->instr,
+ &instr->src[0],
+ nir_src_for_ssa(def));
+ instr->num_components = last_bit;
+
+ return true;
+ }