As a general rule all Shimano index compatible rear derailleurs (obligatory disclaimer: except pre 9-speed Dura Ace) are compatible with any speed shifter. Certainly 7,8 and 9-speed rear derailleurs can be used interchangably on 7,8 and 9-speed cassettes.
Yes, the "9-speed" XT will work fine as a replacement for the "8-speed" Alivio.