Closed llvmbot closed 1 year ago
Eli is right, reordering these loads is invalid.
As far as I know reordering volatiles is perfectly valid. You need a memory barrier if you want to enforce ordering.
From LangRef: "The optimizers must not change the number of volatile operations or change their order of execution relative to other volatile operations."
As far as I know reordering volatiles is perfectly valid. You need a memory barrier if you want to enforce ordering.
Note that -combiner-alias-analysis is an experimental option, and issues are expected.
Flag seems to have been renamed to -combiner-global-alias-analysis. I get the same result with and without it
define i32 @test() {
%X = load volatile i32, i32* inttoptr(i32 8 to i32*)
%Y = load volatile i32, i32* inttoptr(i32 12 to i32*)
%Z = add i32 %Y, 1000
ret i32 %Z
}
Extended Description
llc reorders accesses to volatiles if -combiner-alias-analysis is enabled, although volatiles should not be reordered with regard to each other.
Testcase, which miscompiles at least for sparc and ppc32: define i32 @test() { %X = volatile load i32 inttoptr(i32 8 to i32) %Y = volatile load i32 inttoptr(i32 12 to i32) %Z = add i32 %Y, 1000 ret i32 %Z }
Correct code, from llc -march=ppc32 lwz 3, 8(0) lwz 3, 12(0) addi 3, 3, 1000 blr
Miscompiled code, from llc -march=ppc32 -combiner-alias-analysis lwz 3, 12(0) lwz 4, 8(0) addi 3, 3, 1000 blr