182 lines · plain
1; RUN: opt < %s -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s2 3;; Simple case: a zext nneg can be replaced with a sext. Make sure BasicAA4;; understands that.5define void @t1(i32 %a, i32 %b) {6; CHECK-LABEL: Function: t17; CHECK: NoAlias: float* %gep1, float* %gep28 9 %1 = alloca [8 x float], align 410 %or1 = or i32 %a, 111 %2 = sext i32 %or1 to i6412 %gep1 = getelementptr inbounds float, ptr %1, i64 %213 14 %shl1 = shl i32 %b, 115 %3 = zext nneg i32 %shl1 to i6416 %gep2 = getelementptr inbounds float, ptr %1, i64 %317 18 load float, ptr %gep119 load float, ptr %gep220 ret void21}22 23;; A (zext nneg (sext V)) is equivalent to a (zext (sext V)) as long as the24;; total number of zext+sext bits is the same for both.25define void @t2(i8 %a, i8 %b) {26; CHECK-LABEL: Function: t227; CHECK: NoAlias: float* %gep1, float* %gep228 %1 = alloca [8 x float], align 429 %or1 = or i8 %a, 130 %2 = sext i8 %or1 to i3231 %3 = zext i32 %2 to i6432 %gep1 = getelementptr inbounds float, ptr %1, i64 %333 34 %shl1 = shl i8 %b, 135 %4 = sext i8 %shl1 to i1636 %5 = zext nneg i16 %4 to i6437 %gep2 = getelementptr inbounds float, ptr %1, i64 %538 39 load float, ptr %gep140 load float, ptr %gep241 ret void42}43 44;; Here the %a and %b are knowably non-equal. In this cases we can distribute45;; the zext, preserving the nneg flag, through the shl because it has a nsw flag46define void @t3(i8 %v) {47; CHECK-LABEL: Function: t348; CHECK: NoAlias: <2 x float>* %gep1, <2 x float>* %gep249 %a = or i8 %v, 150 %b = and i8 %v, 251 52 %1 = alloca [8 x float], align 453 %or1 = shl nuw nsw i8 %a, 154 %2 = zext nneg i8 %or1 to i6455 %gep1 = getelementptr inbounds float, ptr %1, i64 %256 57 %m = mul nsw nuw i8 %b, 258 %3 = sext i8 %m to i1659 %4 = zext i16 %3 to i6460 %gep2 = getelementptr inbounds float, ptr %1, i64 %461 62 load <2 x float>, ptr %gep163 load <2 x float>, ptr %gep264 ret void65}66 67;; This is the same as above, but this time the shl does not have the nsw flag.68;; the nneg cannot be kept on the zext.69define void @t4(i8 %v) {70; CHECK-LABEL: Function: t471; CHECK: MayAlias: <2 x float>* %gep1, <2 x float>* %gep272 %a = or i8 %v, 173 %b = and i8 %v, 274 75 %1 = alloca [8 x float], align 476 %or1 = shl nuw i8 %a, 177 %2 = zext nneg i8 %or1 to i6478 %gep1 = getelementptr inbounds float, ptr %1, i64 %279 80 %m = mul nsw nuw i8 %b, 281 %3 = sext i8 %m to i1682 %4 = zext i16 %3 to i6483 %gep2 = getelementptr inbounds float, ptr %1, i64 %484 85 load <2 x float>, ptr %gep186 load <2 x float>, ptr %gep287 ret void88}89 90;; Verify a zext nneg and a zext are understood as the same91define void @t5(ptr %p, i16 %i) {92; CHECK-LABEL: Function: t593; CHECK: NoAlias: i32* %pi, i32* %pi.next94 %i1 = zext nneg i16 %i to i3295 %pi = getelementptr i32, ptr %p, i32 %i196 97 %i.next = add i16 %i, 198 %i.next2 = zext i16 %i.next to i3299 %pi.next = getelementptr i32, ptr %p, i32 %i.next2100 101 load i32, ptr %pi102 load i32, ptr %pi.next103 ret void104}105 106;; This is not very idiomatic, but still possible, verify the nneg is propagated107;; outward. and that no alias is correctly identified.108define void @t6(i8 %a) {109; CHECK-LABEL: Function: t6110; CHECK: NoAlias: float* %gep1, float* %gep2111 %1 = alloca [8 x float], align 4112 %a.add = add i8 %a, 1113 %2 = zext nneg i8 %a.add to i16114 %3 = sext i16 %2 to i32115 %4 = zext i32 %3 to i64116 %gep1 = getelementptr inbounds float, ptr %1, i64 %4117 118 %5 = sext i8 %a to i64119 %gep2 = getelementptr inbounds float, ptr %1, i64 %5120 121 load float, ptr %gep1122 load float, ptr %gep2123 ret void124}125 126;; This is even less idiomatic, but still possible, verify the nneg is not127;; propagated inward. and that may alias is correctly identified.128define void @t7(i8 %a) {129; CHECK-LABEL: Function: t7130; CHECK: MayAlias: float* %gep1, float* %gep2131 %1 = alloca [8 x float], align 4132 %a.add = add i8 %a, 1133 %2 = zext i8 %a.add to i16134 %3 = sext i16 %2 to i32135 %4 = zext nneg i32 %3 to i64136 %gep1 = getelementptr inbounds float, ptr %1, i64 %4137 138 %5 = sext i8 %a to i64139 %gep2 = getelementptr inbounds float, ptr %1, i64 %5140 141 load float, ptr %gep1142 load float, ptr %gep2143 ret void144}145 146;; Verify the nneg survives an implicit trunc of fewer bits then the zext.147define void @t8(i8 %a) {148; CHECK-LABEL: Function: t8149; CHECK: NoAlias: float* %gep1, float* %gep2150 %1 = alloca [8 x float], align 4151 %a.add = add i8 %a, 1152 %2 = zext nneg i8 %a.add to i128153 %gep1 = getelementptr inbounds float, ptr %1, i128 %2154 155 %3 = sext i8 %a to i64156 %gep2 = getelementptr inbounds float, ptr %1, i64 %3157 158 load float, ptr %gep1159 load float, ptr %gep2160 ret void161}162 163;; Ensure that the nneg is never propagated past this trunc and that these164;; casted values are understood as non-equal.165define void @t9(i8 %a) {166; CHECK-LABEL: Function: t9167; CHECK: MayAlias: float* %gep1, float* %gep2168 %1 = alloca [8 x float], align 4169 %a.add = add i8 %a, 1170 %2 = zext i8 %a.add to i16171 %3 = trunc i16 %2 to i1172 %4 = zext nneg i1 %3 to i64173 %gep1 = getelementptr inbounds float, ptr %1, i64 %4174 175 %5 = sext i8 %a to i64176 %gep2 = getelementptr inbounds float, ptr %1, i64 %5177 178 load float, ptr %gep1179 load float, ptr %gep2180 ret void181}182