* left and on the right.
                 * Merge all three into a single extent record.
                 */
-               --*idx;
                left.br_blockcount += new->br_blockcount + right.br_blockcount;
-               xfs_iext_update_extent(ip, state, *idx, &left);
 
-               xfs_iext_remove(ip, *idx + 1, 1, state);
+               xfs_iext_remove(ip, *idx, 1, state);
+               --*idx;
+               xfs_iext_update_extent(ip, state, *idx, &left);
 
                XFS_IFORK_NEXT_SET(ip, whichfork,
                        XFS_IFORK_NEXTENTS(ip, whichfork) - 1);
                 * on the left.
                 * Merge the new allocation with the left neighbor.
                 */
-               --*idx;
                old = left;
-
                left.br_blockcount += new->br_blockcount;
+
+               --*idx;
                xfs_iext_update_extent(ip, state, *idx, &left);
 
                if (cur == NULL) {