I would not worry too much about the re-checking bags issue.
Assuming Madrid is like most other International->Domestic transfers, your bags would be tagged all the way to BCN, but come out on the belt in Madrid for you to go through customs. You would just need to grab your bag, walk "across the line" through customs and immediately drop your bags to continue with you.