llvm-project/polly/test/CodeGen/empty_domain_in_context.ll
Michael Kruse 7a0f7dbf2d
[Polly] Introduce PhaseManager and remove LPM support (#125442) (#167560)
Reapply of a22d1c2225543aa9ae7882f6b1a97ee7b2c95574. Using this PR for
pre-merge CI.

Instead of relying on any pass manager to schedule Polly's passes, add
Polly's own pipeline manager which is seen as a monolithic pass in
LLVM's pass manager. Polly's former passes are now phases of the new
PhaseManager component.

Relying on LLVM's pass manager (the legacy as well as the New Pass
Manager) to manage Polly's phases never was a good fit that the
PhaseManager resolves:

* Polly passes were modifying analysis results, in particular RegionInfo
and ScopInfo. This means that there was not just one unique and
"definite" analysis result, the actual result depended on which analyses
ran prior, and the pass manager was not allowed to throw away cached
analyses or prior SCoP optimizations would have been forgotten. The LLVM
pass manger's persistance of analysis results is not contractual but
designed for caching.

* Polly depends on a particular execution order of passes and regions
(e.g. regression tests, invalidation of consecutive SCoPs). LLVM's pass
manager does not guarantee any excecution order.

* Polly does not completely preserve DominatorTree, RegionInfo,
LoopInfo, or ScalarEvolution, but only as-needed for Polly's own uses.
Because the ScopDetection object stores references to those analyses, it
still had to lie to the pass manager that they would be preserved, or
the pass manager would have released and recomputed the invalidated
analysis objects that ScopDetection/ScopInfo was still referencing. To
ensure that no non-Polly pass would see these not-completely-preserved
analyses, all analyses still had to be thrown away after the
ScopPassManager, respectively with a BarrierNoopPass in case of the LPM.
 
* The NPM's PassInstrumentation wraps the IR unit into an `llvm::Any`
object, but implementations such as PrintIRInstrumentation call
llvm_unreachable on encountering an unknown IR unit, such as SCoPs, with
no extension points to add support. Hence LLVM crashes when dumping IR
between SCoP passes (such as `-print-before-changed` with Polly being
active).

The new PhaseManager uses some command line options that previously
belonged to Polly's legacy passes, such as `-polly-print-detect` (so the
option will continue to work). Hence the LPM support is incompatible
with the new approach and support for it is removed.
2025-11-14 00:45:54 +01:00

87 lines
3.5 KiB
LLVM

; RUN: opt %loadNPMPolly '-passes=polly-custom<optree;opt-isl;codegen>' -S < %s | FileCheck %s
;
; llvm.org/PR35362
; isl codegen does not allow to generate isl_ast_expr from pw_aff which have an
; empty domain. This happens in this case because the pw_aff's domain is
; excluded by the SCoP's parameter context.
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
@c = external local_unnamed_addr global i8
@a = external local_unnamed_addr global i16
@b = external local_unnamed_addr global i8
define void @fn1() {
entry:
%a.promoted = load i16, ptr @a
br label %for.cond
for.cond: ; preds = %for.cond3.for.end_crit_edge, %entry
%inc.lcssa17 = phi i16 [ 0, %for.cond3.for.end_crit_edge ], [ %a.promoted, %entry ]
br label %for.body
for.body: ; preds = %for.cond
%conv = zext i16 %inc.lcssa17 to i32
%div = udiv i32 -286702568, %conv
br i1 undef, label %if.end, label %if.then
if.then: ; preds = %for.body
unreachable
if.end: ; preds = %for.body
br label %for.body5.lr.ph
for.body5.lr.ph: ; preds = %if.end
%tmp = load i8, ptr @b, align 1
%cmp = icmp eq i32 %div, 1
br i1 %cmp, label %for.body5.lr.ph.split.us, label %for.body5.lr.ph.split
for.body5.lr.ph.split.us: ; preds = %for.body5.lr.ph
br label %lor.end.us.peel
lor.end.us.peel: ; preds = %for.body5.lr.ph.split.us
%inc.us.peel = add i16 %inc.lcssa17, 1
br i1 false, label %for.cond3.for.end_crit_edge, label %for.body5.us.peel.next
for.body5.us.peel.next: ; preds = %lor.end.us.peel
br label %lor.end.us
lor.end.us: ; preds = %lor.end.us, %for.body5.us.peel.next
%tmp1 = phi i16 [ %inc.us.peel, %for.body5.us.peel.next ], [ %inc.us, %lor.end.us ]
%inc.us = add i16 %tmp1, 1
%tobool4.us = icmp eq i16 %inc.us, 0
br i1 %tobool4.us, label %for.cond3.for.end_crit_edge, label %lor.end.us
for.body5.lr.ph.split: ; preds = %for.body5.lr.ph
br label %lor.end.peel
lor.end.peel: ; preds = %for.body5.lr.ph.split
%inc.peel = add i16 %inc.lcssa17, 1
br i1 false, label %for.cond3.for.end_crit_edge, label %for.body5.peel.next
for.body5.peel.next: ; preds = %lor.end.peel
br label %lor.end
lor.end: ; preds = %lor.end, %for.body5.peel.next
%tmp2 = phi i16 [ %inc.peel, %for.body5.peel.next ], [ %inc, %lor.end ]
%inc = add i16 %tmp2, 1
%tobool4 = icmp eq i16 %inc, 0
br i1 %tobool4, label %for.cond3.for.end_crit_edge, label %lor.end
for.cond3.for.end_crit_edge: ; preds = %lor.end, %lor.end.peel, %lor.end.us, %lor.end.us.peel
%tmp3 = phi i8 [ %tmp, %lor.end.us.peel ], [ %tmp, %lor.end.peel ], [ %tmp, %lor.end.us ], [ %tmp, %lor.end ]
store i8 4, ptr @c
br label %for.cond
}
; The reference to @b should have been generated from an isl_ast_expr.
; Because isl is unable to generate it in this case, the code generator
; resorted to use the pointer argument of %tmp = load ... .
; It is not important since this code will never be executed.
; CHECK: polly.stmt.lor.end.us.peel:
; CHECK-NEXT: %tmp_p_scalar_2 = load i8, ptr @b
; CHECK-NEXT: store i8 %tmp_p_scalar_2, ptr %tmp3.phiops
; CHECK-NEXT: br label %polly.merge