Extended Description
For the following IR:
@g = global i16 0, align 2
declare void @bar(i32)
define hidden void @foo() {
%1 = load volatile i16, i16* @g, align 2
%2 = sext i16 %1 to i32
call void @bar(i32 %2)
ret void
}
llc -mtriple=aarch64 -global-isel generates for the load followed by sext:
adrp x8, g
add x8, x8, :lo12:g
ldrh wzr, [x8]
ldrsh w0, [x8]
g is loaded twice, once with a zero-extending load which is discarded, and second with a sign-extending load. For a volatile load we should be generating only a single load instruction.