[PATCH] D144445: [ConstantFold][InstSimplify] folding load for constant global all-element-equal arrays and structs

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 01:44:57 PST 2023


khei4 added a comment.

@StephenFan Thank you for the review! (I have noticed alive2's link in the summary is broken, I fixed it.)

> Is it correct if we load with the same type as the const array but the load's pointer operand is with the i8* type?
>
>   define i32 @load_gep_const_alleq_array(i64 %idx) {
>     %gep = getelementptr inbounds i8, ptr @constalleqarray, i64 %idx
>     %load = load i32, ptr %gep
>     ret i32 %load
>   }

On the above example, GEP type only affects the offset calc strides, even if `idx` is not multiples of 4 the load would become undefined and any value could be returned. 
So this is ok as long as load's target type corresponds to the element type.
(If I misunderstood, please correct :) )

proof: https://alive2.llvm.org/ce/z/_yEafa


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144445/new/

https://reviews.llvm.org/D144445



More information about the llvm-commits mailing list