Hi,
We’ve noticed some regressions as a result of removing MODereferencable from loads in visitLoad from SelectionDAGBuilder.cpp. The problematic code is this condition from Loads.cpp:
if (!GEP->accumulateConstantOffset(DL, Offset) || Offset.isNegative() ||
!Offset.urem(APInt(Offset.getBitWidth(), Alignment.value()))
.isMinValue())
What we’re seeing is that our loads fail to get the dereferencable flag for 2 reasons:
- The Loop Strength Reduction pass is moving the pointer forward, causing the offset to look negative, even though it’s not. Notice that -15 is added to the pointer from constant + 15 (I’ve added ** in the code for emphasis)
%uglygep21 = getelementptr i8, i8* bitcast (i16* getelementptr inbounds ([78 x [16 x i16]], [78 x [16 x i16]]* @data_index, i32 0, i32 0, i32 **15**) to i8*), i32 %lsr.iv ; uid:1984
%uglygep2122 = bitcast i8* %uglygep21 to i16* ; uid:1985
%scevgep = getelementptr i16, i16* %uglygep2122, i32 **-15** ; uid:1986
- The load comes from PHI, so we don’t see that the pointer is coming from a constant.
In clang15 (or prior to bb70b5d40652207c0bd3d385def10ef3ef1d45b4), the dereferencable flag was applied without calling isDereferenceableAndAlignedPointer. This allowed us to use vectorization on the loads.
This is an example of the code we want to be able to select into dereferencable loads: https://godbolt.org/z/qde9Meeqs
Does anyone know how to address this?
@arsenm - the commits that changed setting MODereferenceable this are on your name, are you aware of this issue?
Best regards,
Betzalel