Home | History | Annotate | Download | only in Steensgaard
      1 ; Makes sure that we give up on some pathological cases with inttoptr/ptrtoint
      2 ;
      3 ; @ptr_test was generated from the following C code:
      4 ;  void ptr_test() {
      5 ;    int* A;
      6 ;    unsigned long RefCopy = 0;
      7 ;    for (int i = 0; i < 8*sizeof(&A); ++i) {
      8 ;      if ((unsigned long)&A & (1UL << i))
      9 ;        RefCopy |= 1UL << i;
     10 ;    }
     11 ;
     12 ;    int** AliasA1 = (int**)RefCopy;
     13 ;    int* ShouldAliasA = *AliasA1;
     14 ;  }
     15 
     16 ; RUN: opt < %s -disable-basicaa -cfl-steens-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
     17 
     18 ; CHECK: Function: ptr_test
     19 define void @ptr_test() #0 {
     20   ; CHECK: MayAlias: i32** %A, i32** %ShouldAliasA
     21   ; CHECK-NOT: %AliasA1
     22 entry:
     23   %A = alloca i32*, align 8
     24   %RefCopy = alloca i64, align 8
     25   %i = alloca i32, align 4
     26   %AliasA1 = alloca i32**, align 8
     27   %ShouldAliasA = alloca i32*, align 8
     28   store i64 0, i64* %RefCopy, align 8
     29   store i32 0, i32* %i, align 4
     30   br label %for.cond
     31 
     32 for.cond:                                         ; preds = %for.inc, %entry
     33   %0 = load i32, i32* %i, align 4
     34   %conv = sext i32 %0 to i64
     35   %cmp = icmp ult i64 %conv, 64
     36   br i1 %cmp, label %for.body, label %for.end
     37 
     38 for.body:                                         ; preds = %for.cond
     39   %1 = ptrtoint i32** %A to i64
     40   %2 = load i32, i32* %i, align 4
     41   %sh_prom = zext i32 %2 to i64
     42   %shl = shl i64 1, %sh_prom
     43   %and = and i64 %1, %shl
     44   %tobool = icmp ne i64 %and, 0
     45   br i1 %tobool, label %if.then, label %if.end
     46 
     47 if.then:                                          ; preds = %for.body
     48   %3 = load i32, i32* %i, align 4
     49   %sh_prom2 = zext i32 %3 to i64
     50   %shl3 = shl i64 1, %sh_prom2
     51   %4 = load i64, i64* %RefCopy, align 8
     52   %or = or i64 %4, %shl3
     53   store i64 %or, i64* %RefCopy, align 8
     54   br label %if.end
     55 
     56 if.end:                                           ; preds = %if.then, %for.body
     57   br label %for.inc
     58 
     59 for.inc:                                          ; preds = %if.end
     60   %5 = load i32, i32* %i, align 4
     61   %inc = add nsw i32 %5, 1
     62   store i32 %inc, i32* %i, align 4
     63   br label %for.cond
     64 
     65 for.end:                                          ; preds = %for.cond
     66   %6 = load i64, i64* %RefCopy, align 8
     67   %7 = inttoptr i64 %6 to i32**
     68   store i32** %7, i32*** %AliasA1, align 8
     69   %8 = load i32**, i32*** %AliasA1, align 8
     70   %9 = load i32*, i32** %8, align 8
     71   store i32* %9, i32** %ShouldAliasA, align 8
     72   ret void
     73 }
     74