[InstCombine] Allow to limit the max number of iterations
Summary:
This patch teaches InstCombine to accept a new parameter: maximum number of iterations over functions.
InstCombine tries to simplify instructions by iterating over the whole function until the function stops changing. As a consequence, the last iteration before reaching a fixpoint visits all instructions in the worklist and never performs any rewrites.
Bounding the number of iterations can have 2 benefits:
* In case the users of the pass can make a good guess about the number of required iterations, we can save the time normally spent on the last iteration that doesn't change anything.
* When the wants to use InstCombine as a cleanup pass, it may be enough to run just a few iterations and stop even before reaching a fixpoint. This can be also useful for implementing a lightweight pass pipeline (think `-O1`).
This patch does not change the behavior of opt or Clang -- limiting the number of iterations is entirely opt-in.
Reviewers: fhahn, davide, spatel, foad, nlopes, grosser, lebedev.ri, nikic, xbolva00
Reviewed By: spatel
Subscribers: craig.topper, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71145
2019-12-19 02:48:54 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
|
|
; RUN: opt < %s -instcombine --instcombine-max-iterations=0 -S | FileCheck %s --check-prefix=ZERO
|
|
|
|
; RUN: opt < %s -instcombine --instcombine-max-iterations=1 -S | FileCheck %s --check-prefix=ONE
|
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s --check-prefix=FIXPOINT
|
2020-03-29 01:15:31 +08:00
|
|
|
; RUN: not --crash opt < %s -instcombine -S --instcombine-infinite-loop-threshold=2 2>&1 | FileCheck %s --check-prefix=LOOP
|
[InstCombine] Allow to limit the max number of iterations
Summary:
This patch teaches InstCombine to accept a new parameter: maximum number of iterations over functions.
InstCombine tries to simplify instructions by iterating over the whole function until the function stops changing. As a consequence, the last iteration before reaching a fixpoint visits all instructions in the worklist and never performs any rewrites.
Bounding the number of iterations can have 2 benefits:
* In case the users of the pass can make a good guess about the number of required iterations, we can save the time normally spent on the last iteration that doesn't change anything.
* When the wants to use InstCombine as a cleanup pass, it may be enough to run just a few iterations and stop even before reaching a fixpoint. This can be also useful for implementing a lightweight pass pipeline (think `-O1`).
This patch does not change the behavior of opt or Clang -- limiting the number of iterations is entirely opt-in.
Reviewers: fhahn, davide, spatel, foad, nlopes, grosser, lebedev.ri, nikic, xbolva00
Reviewed By: spatel
Subscribers: craig.topper, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71145
2019-12-19 02:48:54 +08:00
|
|
|
|
2020-03-29 01:15:31 +08:00
|
|
|
; Based on builtin-dynamic-object-size.ll. This requires multiple iterations of
|
[InstCombine] Allow to limit the max number of iterations
Summary:
This patch teaches InstCombine to accept a new parameter: maximum number of iterations over functions.
InstCombine tries to simplify instructions by iterating over the whole function until the function stops changing. As a consequence, the last iteration before reaching a fixpoint visits all instructions in the worklist and never performs any rewrites.
Bounding the number of iterations can have 2 benefits:
* In case the users of the pass can make a good guess about the number of required iterations, we can save the time normally spent on the last iteration that doesn't change anything.
* When the wants to use InstCombine as a cleanup pass, it may be enough to run just a few iterations and stop even before reaching a fixpoint. This can be also useful for implementing a lightweight pass pipeline (think `-O1`).
This patch does not change the behavior of opt or Clang -- limiting the number of iterations is entirely opt-in.
Reviewers: fhahn, davide, spatel, foad, nlopes, grosser, lebedev.ri, nikic, xbolva00
Reviewed By: spatel
Subscribers: craig.topper, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71145
2019-12-19 02:48:54 +08:00
|
|
|
; InstCombine to reach a fixpoint.
|
|
|
|
|
2020-03-29 01:15:31 +08:00
|
|
|
define i64 @weird_identity_but_ok(i64 %sz) {
|
|
|
|
; ZERO-LABEL: @weird_identity_but_ok(
|
|
|
|
; ZERO-NEXT: entry:
|
|
|
|
; ZERO-NEXT: [[CALL:%.*]] = tail call i8* @malloc(i64 [[SZ:%.*]])
|
|
|
|
; ZERO-NEXT: [[CALC_SIZE:%.*]] = tail call i64 @llvm.objectsize.i64.p0i8(i8* [[CALL]], i1 false, i1 true, i1 true)
|
|
|
|
; ZERO-NEXT: tail call void @free(i8* [[CALL]])
|
|
|
|
; ZERO-NEXT: ret i64 [[CALC_SIZE]]
|
|
|
|
;
|
|
|
|
; ONE-LABEL: @weird_identity_but_ok(
|
|
|
|
; ONE-NEXT: entry:
|
|
|
|
; ONE-NEXT: [[TMP0:%.*]] = sub i64 [[SZ:%.*]], 0
|
|
|
|
; ONE-NEXT: [[TMP1:%.*]] = icmp ult i64 [[SZ]], 0
|
|
|
|
; ONE-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 0, i64 [[TMP0]]
|
|
|
|
; ONE-NEXT: ret i64 [[TMP2]]
|
|
|
|
;
|
|
|
|
; FIXPOINT-LABEL: @weird_identity_but_ok(
|
|
|
|
; FIXPOINT-NEXT: entry:
|
|
|
|
; FIXPOINT-NEXT: ret i64 [[SZ:%.*]]
|
|
|
|
;
|
|
|
|
; LOOP: LLVM ERROR: Instruction Combining seems stuck in an infinite loop after 2 iterations.
|
|
|
|
entry:
|
|
|
|
%call = tail call i8* @malloc(i64 %sz)
|
|
|
|
%calc_size = tail call i64 @llvm.objectsize.i64.p0i8(i8* %call, i1 false, i1 true, i1 true)
|
|
|
|
tail call void @free(i8* %call)
|
|
|
|
ret i64 %calc_size
|
[InstCombine] Allow to limit the max number of iterations
Summary:
This patch teaches InstCombine to accept a new parameter: maximum number of iterations over functions.
InstCombine tries to simplify instructions by iterating over the whole function until the function stops changing. As a consequence, the last iteration before reaching a fixpoint visits all instructions in the worklist and never performs any rewrites.
Bounding the number of iterations can have 2 benefits:
* In case the users of the pass can make a good guess about the number of required iterations, we can save the time normally spent on the last iteration that doesn't change anything.
* When the wants to use InstCombine as a cleanup pass, it may be enough to run just a few iterations and stop even before reaching a fixpoint. This can be also useful for implementing a lightweight pass pipeline (think `-O1`).
This patch does not change the behavior of opt or Clang -- limiting the number of iterations is entirely opt-in.
Reviewers: fhahn, davide, spatel, foad, nlopes, grosser, lebedev.ri, nikic, xbolva00
Reviewed By: spatel
Subscribers: craig.topper, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71145
2019-12-19 02:48:54 +08:00
|
|
|
}
|
2020-03-29 01:15:31 +08:00
|
|
|
|
|
|
|
declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1)
|
|
|
|
declare i8* @malloc(i64)
|
|
|
|
declare void @free(i8*)
|