[llvm] 413b7ac - [BasicAA] Add test showing 32 bit overflow issue for GEPs.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 1 03:38:15 PDT 2021


Author: Florian Hahn
Date: 2021-10-01T11:37:56+01:00
New Revision: 413b7ac6b535dfb4c57c2842388a2071901b9d56

URL: https://github.com/llvm/llvm-project/commit/413b7ac6b535dfb4c57c2842388a2071901b9d56
DIFF: https://github.com/llvm/llvm-project/commit/413b7ac6b535dfb4c57c2842388a2071901b9d56.diff

LOG: [BasicAA] Add test showing 32 bit overflow issue for GEPs.

This patch additional tests with i64 GEP indices for 32 bit pointers.
@mustalias_overflow_in_32_bit_add_mul_gep highlights a case where
BasicAA currently incorrectly determines noalias.

Modeled in Alive2 for 32 bit pointers: https://alive2.llvm.org/ce/z/HHjQgb
Modeled in Alive2 for 64 bit pointers: https://alive2.llvm.org/ce/z/DoWK2c

Added: 
    llvm/test/Analysis/BasicAA/gep-implicit-trunc-32-bit-pointers.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/BasicAA/gep-implicit-trunc-32-bit-pointers.ll b/llvm/test/Analysis/BasicAA/gep-implicit-trunc-32-bit-pointers.ll
new file mode 100644
index 0000000000000..aac593278ef6d
--- /dev/null
+++ b/llvm/test/Analysis/BasicAA/gep-implicit-trunc-32-bit-pointers.ll
@@ -0,0 +1,56 @@
+; RUN: opt -basic-aa -aa-eval -print-all-alias-modref-info -disable-output %s 2>&1 | FileCheck %s
+
+target datalayout = "p:32:32:32"
+
+; Test cases with i64 bit GEP indices that will get truncated implicitly to 32
+; bit due to the datalayout.
+
+declare void @llvm.assume(i1)
+
+define void @mustalias_overflow_in_32_bit_constants(i8* %ptr) {
+; CHECK-LABEL: Function: mustalias_overflow_in_32_bit_constants: 3 pointers, 0 call sites
+; CHECK-NEXT:    MustAlias: i8* %gep.1, i8* %ptr
+; CHECK-NEXT:    MustAlias:    i8* %gep.2, i8* %ptr
+; CHECK-NEXT:    MustAlias:    i8* %gep.1, i8* %gep.2
+;
+  %gep.1 = getelementptr i8, i8* %ptr, i64 4294967296
+  store i8 0, i8* %gep.1
+  %gep.2 = getelementptr i8, i8* %ptr, i64 0
+  store i8 1, i8* %gep.2
+  ret void
+}
+
+define void @noalias_overflow_in_32_bit_constants(i8* %ptr) {
+; CHECK-LABEL: Function: noalias_overflow_in_32_bit_constants: 3 pointers, 0 call sites
+; CHECK-NEXT:    MustAlias: i8* %gep.1, i8* %ptr
+; CHECK-NEXT:    NoAlias:  i8* %gep.2, i8* %ptr
+; CHECK-NEXT:    NoAlias:  i8* %gep.1, i8* %gep.2
+;
+  %gep.1 = getelementptr i8, i8* %ptr, i64 4294967296
+  store i8 0, i8* %gep.1
+  %gep.2 = getelementptr i8, i8* %ptr, i64 1
+  store i8 1, i8* %gep.2
+  ret void
+}
+
+; FIXME: Currently we incorrectly determine NoAlias for %gep.1 and %gep.2. The
+; GEP indices get implicitly truncated to 32 bit, so multiples of 2^32
+; (=4294967296) will be 0.
+; See https://alive2.llvm.org/ce/z/HHjQgb.
+define void @mustalias_overflow_in_32_bit_add_mul_gep(i8* %ptr, i64 %i) {
+; CHECK-LABEL: Function: mustalias_overflow_in_32_bit_add_mul_gep: 3 pointers, 1 call sites
+; CHECK-NEXT:    NoAlias:  i8* %gep.1, i8* %ptr
+; CHECK-NEXT:    NoAlias:  i8* %gep.2, i8* %ptr
+; CHECK-NEXT:    NoAlias:  i8* %gep.1, i8* %gep.2
+;
+  %s.1 = icmp sgt i64 %i, 0
+  call void @llvm.assume(i1 %s.1)
+
+  %mul = mul nuw nsw i64 %i, 4294967296
+  %add = add nuw nsw i64 %mul, %i
+  %gep.1 = getelementptr i8, i8* %ptr, i64 %add
+  store i8 0, i8* %gep.1
+  %gep.2 = getelementptr i8, i8* %ptr, i64 %i
+  store i8 1, i8* %gep.2
+  ret void
+}


        


More information about the llvm-commits mailing list