Files
clang-p2996/llvm/test/Transforms/Attributor/wrapper.ll
Johannes Doerfert bf789b1957 [Attributor] Replace AAValueSimplify with AAPotentialValues
For the longest time we used `AAValueSimplify` and
`genericValueTraversal` to determine "potential values". This was
problematic for many reasons:
- We recomputed the result a lot as there was no caching for the 9
  locations calling `genericValueTraversal`.
- We added the idea of "intra" vs. "inter" procedural simplification
  only as an afterthought. `genericValueTraversal` did offer an option
  but `AAValueSimplify` did not. Thus, we might end up with "too much"
  simplification in certain situations and then gave up on it.
- Because `genericValueTraversal` was not a real `AA` we ended up with
  problems like the infinite recursion bug (#54981) as well as code
  duplication.

This patch introduces `AAPotentialValues` and replaces the
`AAValueSimplify` uses with it. `genericValueTraversal` is folded into
`AAPotentialValues` as are the instruction simplifications performed in
`AAValueSimplify` before. We further distinguish "intra" and "inter"
procedural simplification now.

`AAValueSimplify` was not deleted as we haven't ported the
re-materialization of instructions yet. There are other differences over
the former handling, e.g., we may not fold trivially foldable
instructions right now, e.g., `add i32 1, 1` is not folded to `i32 2`
but if an operand would be simplified to `i32 1` we would fold it still.

We are also even more aware of function/SCC boundaries in CGSCC passes,
which is good even if some tests look like they regress.

Fixes: https://github.com/llvm/llvm-project/issues/54981

Note: A previous version was flawed and consequently reverted in
      6555558a80.
2022-07-19 16:24:42 -05:00

86 lines
2.0 KiB
LLVM

; RUN: opt -passes=attributor-cgscc -attributor-annotate-decl-cs -attributor-allow-shallow-wrappers -S < %s | FileCheck %s --check-prefix=CHECK
; TEST 1: simple test, without argument
; A wrapper will be generated for this function, Check the wrapper first
; CHECK-NOT: Function Attrs:
; CHECK: define linkonce i32 @inner1()
; CHECK: tail call i32 @0()
; CHECK: ret
;
; Check the original function, which is wrapped and becomes anonymous
; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
; CHECK: define internal i32 @0()
; CHECK: ret i32 1
define linkonce i32 @inner1() {
entry:
%a = alloca i32
store i32 1, i32* %a
%b = load i32, i32* %a
ret i32 %b
}
; Check for call
; CHECK: define i32 @outer1
; CHECK: call i32 @inner1
; CHECK: ret
define i32 @outer1() {
entry:
%ret = call i32 @inner1()
ret i32 %ret
}
; TEST 2: with argument
; CHECK-NOT: Function Attrs
; CHECK: define linkonce i32 @inner2(i32 %a, i32 %b)
; CHECK: tail call i32 @1(i32 %a, i32 %b)
; CHECK: ret
;
; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
; CHECK: define internal i32 @1(i32 %a, i32 %b)
; CHECK: %c = add i32 %a, %b
; CHECK: ret i32 %c
define linkonce i32 @inner2(i32 %a, i32 %b) {
entry:
%c = add i32 %a, %b
ret i32 %c
}
; CHECK: define i32 @outer2
; CHECK: call i32 @inner2
; CHECK: ret
define i32 @outer2() {
entry:
%ret = call i32 @inner2(i32 1, i32 2)
ret i32 %ret
}
; TEST 3: check nocurse
; This function calls itself, there will be no attribute
; CHECK-NOT: Function Attrs
; CHECK: define linkonce i32 @inner3(i32 %0)
; CHECK: tail call i32 @2(i32 %0)
; CHECK: ret
;
; CHECK-NOT: Function Attrs:
; CHECK: define internal i32 @2(i32 %0)
define linkonce i32 @inner3(i32) {
entry:
%1 = alloca i32
store i32 %0, i32* %1
br label %2
2:
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 4
br i1 %4, label %5, label %9
5:
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
%8 = call i32 @inner3(i32 %7)
store i32 %8, i32* %1
br label %2
9:
%10 = load i32, i32* %1
ret i32 %10
}