[llvm] 6e36859 - [BasicAA] Extend test coverage for GEP modulo logic.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 7 12:17:45 PDT 2021
Author: Florian Hahn
Date: 2021-04-07T20:13:35+01:00
New Revision: 6e36859a84df8add520d5f48f15eea236e2b32e2
URL: https://github.com/llvm/llvm-project/commit/6e36859a84df8add520d5f48f15eea236e2b32e2
DIFF: https://github.com/llvm/llvm-project/commit/6e36859a84df8add520d5f48f15eea236e2b32e2.diff
LOG: [BasicAA] Extend test coverage for GEP modulo logic.
Add a few additional test cases which combine multiplies with
powers-of-2, different wrapping flags.
Added:
Modified:
llvm/test/Analysis/BasicAA/gep-modulo.ll
Removed:
################################################################################
diff --git a/llvm/test/Analysis/BasicAA/gep-modulo.ll b/llvm/test/Analysis/BasicAA/gep-modulo.ll
index e5aa4901adee9..4c3e547e70369 100644
--- a/llvm/test/Analysis/BasicAA/gep-modulo.ll
+++ b/llvm/test/Analysis/BasicAA/gep-modulo.ll
@@ -81,6 +81,97 @@ define void @may_overflow_mul_sub_i64([16 x i8]* %ptr, i64 %idx) {
ret void
}
+define void @nuw_nsw_mul_sub_i64([16 x i8]* %ptr, i64 %idx) {
+; CHECK-LABEL: Function: nuw_nsw_mul_sub_i64: 3 pointers, 0 call sites
+; CHECK-NEXT: MayAlias: [16 x i8]* %ptr, i8* %gep.idx
+; CHECK-NEXT: PartialAlias: [16 x i8]* %ptr, i8* %gep.3
+; CHECK-NEXT: NoAlias: i8* %gep.3, i8* %gep.idx
+;
+ %mul = mul nuw nsw i64 %idx, 5
+ %sub = sub nuw nsw i64 %mul, 1
+ %gep.idx = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 %sub
+ store i8 0, i8* %gep.idx, align 1
+ %gep.3 = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 3
+ store i8 1, i8* %gep.3, align 1
+ ret void
+}
+
+define void @only_nsw_mul_sub_i64([16 x i8]* %ptr, i64 %idx) {
+; CHECK-LABEL: Function: only_nsw_mul_sub_i64: 3 pointers, 0 call sites
+; CHECK-NEXT: MayAlias: [16 x i8]* %ptr, i8* %gep.idx
+; CHECK-NEXT: PartialAlias: [16 x i8]* %ptr, i8* %gep.3
+; CHECK-NEXT: NoAlias: i8* %gep.3, i8* %gep.idx
+;
+ %mul = mul nsw i64 %idx, 5
+ %sub = sub nsw i64 %mul, 1
+ %gep.idx = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 %sub
+ store i8 0, i8* %gep.idx, align 1
+ %gep.3 = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 3
+ store i8 1, i8* %gep.3, align 1
+ ret void
+}
+
+define void @only_nuw_mul_sub_i64([16 x i8]* %ptr, i64 %idx) {
+; CHECK-LABEL: Function: only_nuw_mul_sub_i64: 3 pointers, 0 call sites
+; CHECK-NEXT: MayAlias: [16 x i8]* %ptr, i8* %gep.idx
+; CHECK-NEXT: PartialAlias: [16 x i8]* %ptr, i8* %gep.3
+; CHECK-NEXT: NoAlias: i8* %gep.3, i8* %gep.idx
+;
+ %mul = mul nuw i64 %idx, 5
+ %sub = sub nuw i64 %mul, 1
+ %gep.idx = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 %sub
+ store i8 0, i8* %gep.idx, align 1
+ %gep.3 = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 3
+ store i8 1, i8* %gep.3, align 1
+ ret void
+}
+
+define void @may_overflow_mul_pow2_sub_i64([16 x i8]* %ptr, i64 %idx) {
+; CHECK-LABEL: Function: may_overflow_mul_pow2_sub_i64: 3 pointers, 0 call sites
+; CHECK-NEXT: MayAlias: [16 x i8]* %ptr, i8* %gep.idx
+; CHECK-NEXT: PartialAlias: [16 x i8]* %ptr, i8* %gep.3
+; CHECK-NEXT: NoAlias: i8* %gep.3, i8* %gep.idx
+;
+ %mul = mul i64 %idx, 8
+ %sub = sub i64 %mul, 1
+ %gep.idx = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 %sub
+ store i8 0, i8* %gep.idx, align 1
+ %gep.3 = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 3
+ store i8 1, i8* %gep.3, align 1
+ ret void
+}
+
+; Multiplies by power-of-2 preserves modulo and the sub does not wrap.
+define void @mul_pow2_sub_nsw_nuw_i64([16 x i8]* %ptr, i64 %idx) {
+; CHECK-LABEL: Function: mul_pow2_sub_nsw_nuw_i64: 3 pointers, 0 call sites
+; CHECK-NEXT: MayAlias: [16 x i8]* %ptr, i8* %gep.idx
+; CHECK-NEXT: PartialAlias: [16 x i8]* %ptr, i8* %gep.3
+; CHECK-NEXT: NoAlias: i8* %gep.3, i8* %gep.idx
+;
+ %mul = mul i64 %idx, 8
+ %sub = sub nuw nsw i64 %mul, 1
+ %gep.idx = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 %sub
+ store i8 0, i8* %gep.idx, align 1
+ %gep.3 = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 3
+ store i8 1, i8* %gep.3, align 1
+ ret void
+}
+
+define void @may_overflow_shl_sub_i64([16 x i8]* %ptr, i64 %idx) {
+; CHECK-LABEL: Function: may_overflow_shl_sub_i64: 3 pointers, 0 call sites
+; CHECK-NEXT: MayAlias: [16 x i8]* %ptr, i8* %gep.idx
+; CHECK-NEXT: PartialAlias: [16 x i8]* %ptr, i8* %gep.3
+; CHECK-NEXT: MayAlias: i8* %gep.3, i8* %gep.idx
+;
+ %mul = shl i64 %idx, 2
+ %sub = sub i64 %mul, 1
+ %gep.idx = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 %sub
+ store i8 0, i8* %gep.idx, align 1
+ %gep.3 = getelementptr [16 x i8], [16 x i8]* %ptr, i32 0, i64 3
+ store i8 1, i8* %gep.3, align 1
+ ret void
+}
+
; %gep.idx and %gep.3 must-alias if %mul overflows (e.g. %idx == 110).
define void @may_overflow_i32_sext([16 x i8]* %ptr, i32 %idx) {
; CHECK-LABEL: Function: may_overflow_i32_sext: 3 pointers, 0 call sites
More information about the llvm-commits
mailing list