Files
clang-p2996/llvm/test/Transforms/IndVarSimplify/pr50506.ll
Nikita Popov dcf4b733ef [SCEVExpander] Make CanonicalMode handing in isSafeToExpand() more robust (PR50506)
isSafeToExpand() for addrecs depends on whether the SCEVExpander
will be used in CanonicalMode. At least one caller currently gets
this wrong, resulting in PR50506.

Fix this by a) making the CanonicalMode argument on the freestanding
functions required and b) adding member functions on SCEVExpander
that automatically take the SCEVExpander mode into account. We can
use the latter variant nearly everywhere, and thus make sure that
there is no chance of CanonicalMode mismatch.

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

Differential Revision: https://reviews.llvm.org/D129630
2022-07-14 14:41:51 +02:00

44 lines
1.4 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -indvars < %s | FileCheck %s
; This test used to assert when expanding an addrec into a loop without
; preheader.
define void @test(ptr %tgt) {
; CHECK-LABEL: @test(
; CHECK-NEXT: bb31:
; CHECK-NEXT: indirectbr ptr [[TGT:%.*]], [label [[EXIT:%.*]], label %bb33]
; CHECK: exit:
; CHECK-NEXT: ret void
; CHECK: bb33:
; CHECK-NEXT: [[TMP34:%.*]] = phi i32 [ [[TMP50:%.*]], [[BB49:%.*]] ], [ 0, [[BB31:%.*]] ]
; CHECK-NEXT: br i1 false, label [[BB40_PREHEADER:%.*]], label [[BB49]]
; CHECK: bb40.preheader:
; CHECK-NEXT: br label [[BB40:%.*]]
; CHECK: bb40:
; CHECK-NEXT: br label [[BB40]]
; CHECK: bb49:
; CHECK-NEXT: [[TMP50]] = add i32 [[TMP34]], 1
; CHECK-NEXT: br label [[BB33:%.*]]
;
bb31:
indirectbr ptr %tgt, [label %exit, label %bb33]
exit:
ret void
bb33: ; preds = %bb49, %bb31
%tmp34 = phi i32 [ %tmp50, %bb49 ], [ 0, %bb31 ]
%tmp36 = add i32 %tmp34, 1
br i1 false, label %bb40, label %bb49
bb40: ; preds = %bb38, %bb37
%tmp41 = phi i32 [ %tmp36, %bb33 ], [ %tmp39, %bb40 ]
%tmp39 = add i32 %tmp41, 0
br label %bb40
bb49: ; preds = %bb35
%tmp50 = add i32 %tmp34, 1
br label %bb33
}