An image decoding method performed by a decoding apparatus, the method comprising: obtaining information on a merge index from a bitstream; deriving a history-based motion vector prediction, HMVP, buffer for a current block; deriving merge candidates for configuring a merge candidate list for the current block, wherein the merge candidates include spatial candidates derived based on spatial candidate blocks and a temporal candidate derived based on a temporal candidate block, wherein an HMVP candidate comprised in the HMVP buffer is inserted as a merge candidate of the merge candidate list, wherein the HMVP candidate is inserted after the spatial candidates and the temporal candidate in the merge candidate list; deriving motion information of the current block based on the HMVP candidate in the merge candidate list; generating prediction samples for the current block based on the motion information; and generating reconstructed samples based on the prediction samples, wherein the HMVP candidate among the merge candidates comprised in the merge candidate list is indicated based on the merge index, wherein the current block is related to a coding unit, CU, which is split from a coding tree unit, CTU, wherein a current picture includes more than one slices, wherein a slice included in the current picture includes more than one CTU rows, wherein the HMVP buffer is updated based on motion information of a previous block, wherein for a slice of which a first-ordered CTU is other than a first-ordered CTU of a CTU row of the current picture, the HMVP buffer is initialized at a first-ordered CTU per each CTU row of the slice, wherein the method further comprises determining, for a current slice of which a first-ordered CTU is other than the first-ordered CTU of the CTU row of the current picture, whether the CTU is a first-ordered CTU in a CTU row of the current slice, wherein the HMVP buffer for the current block is derived based on the result of the determination, and wherein based on the result of the determining that, for a current slice of which a first-ordered CTU is other than the first-ordered CTU of the CTU row of the current picture, the CTU is the first-ordered CTU in the CTU row of the current slice, the HMVP buffer is initialized for the CTU. obtaining information on a merge index from a bitstream; deriving a history-based motion vector prediction, HMVP, buffer for a current block; deriving merge candidates for configuring a merge candidate list for the current block, wherein the merge candidates include spatial candidates derived based on spatial candidate blocks and a temporal candidate derived based on a temporal candidate block, wherein an HMVP candidate comprised in the HMVP buffer is inserted as a merge candidate of the merge candidate list, wherein the HMVP candidate is inserted after the spatial candidates and the temporal candidate in the merge candidate list; deriving motion information of the current block based on the HMVP candidate in the merge candidate list; generating prediction samples for the current block based on the motion information; and generating reconstructed samples based on the prediction samples, wherein the HMVP candidate among the merge candidates comprised in the merge candidate list is indicated based on the merge index, wherein the current block is related to a coding unit, CU, which is split from a coding tree unit, CTU, wherein a current picture includes more than one slices, wherein a slice included in the current picture includes more than one CTU rows, wherein the HMVP buffer is updated based on motion information of a previous block, wherein for a slice of which a first-ordered CTU is other than a first-ordered CTU of a CTU row of the current picture, the HMVP buffer is initialized at a first-ordered CTU per each CTU row of the slice, wherein the method further comprises determining, for a current slice of which a first-ordered CTU is other than the first-ordered CTU of the CTU row of the current picture, whether the CTU is a first-ordered CTU in a CTU row of the current slice, wherein the HMVP buffer for the current block is derived based on the result of the determination, and wherein based on the result of the determining that, for a current slice of which a first-ordered CTU is other than the first-ordered CTU of the CTU row of the current picture, the CTU is the first-ordered CTU in the CTU row of the current slice, the HMVP buffer is initialized for the CTU.