branch-alias.ll 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. ; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
  16. ; CHECK: Function: ptr_test
  17. define void @ptr_test() #0 {
  18. ; CHECK: MayAlias: i32** %A, i32** %ShouldAliasA
  19. ; CHECK-NOT: %AliasA1
  20. entry:
  21. %A = alloca i32*, align 8
  22. %RefCopy = alloca i64, align 8
  23. %i = alloca i32, align 4
  24. %AliasA1 = alloca i32**, align 8
  25. %ShouldAliasA = alloca i32*, align 8
  26. store i64 0, i64* %RefCopy, align 8
  27. store i32 0, i32* %i, align 4
  28. br label %for.cond
  29. for.cond: ; preds = %for.inc, %entry
  30. %0 = load i32, i32* %i, align 4
  31. %conv = sext i32 %0 to i64
  32. %cmp = icmp ult i64 %conv, 64
  33. br i1 %cmp, label %for.body, label %for.end
  34. for.body: ; preds = %for.cond
  35. %1 = ptrtoint i32** %A to i64
  36. %2 = load i32, i32* %i, align 4
  37. %sh_prom = zext i32 %2 to i64
  38. %shl = shl i64 1, %sh_prom
  39. %and = and i64 %1, %shl
  40. %tobool = icmp ne i64 %and, 0
  41. br i1 %tobool, label %if.then, label %if.end
  42. if.then: ; preds = %for.body
  43. %3 = load i32, i32* %i, align 4
  44. %sh_prom2 = zext i32 %3 to i64
  45. %shl3 = shl i64 1, %sh_prom2
  46. %4 = load i64, i64* %RefCopy, align 8
  47. %or = or i64 %4, %shl3
  48. store i64 %or, i64* %RefCopy, align 8
  49. br label %if.end
  50. if.end: ; preds = %if.then, %for.body
  51. br label %for.inc
  52. for.inc: ; preds = %if.end
  53. %5 = load i32, i32* %i, align 4
  54. %inc = add nsw i32 %5, 1
  55. store i32 %inc, i32* %i, align 4
  56. br label %for.cond
  57. for.end: ; preds = %for.cond
  58. %6 = load i64, i64* %RefCopy, align 8
  59. %7 = inttoptr i64 %6 to i32**
  60. store i32** %7, i32*** %AliasA1, align 8
  61. %8 = load i32**, i32*** %AliasA1, align 8
  62. %9 = load i32*, i32** %8, align 8
  63. store i32* %9, i32** %ShouldAliasA, align 8
  64. ret void
  65. }