[PATCH] D155473: [GuardWidening][Test] Illustrate incorrect insertion point case

Aleksandr Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 08:34:06 PDT 2023


aleksandr.popov created this revision.
Herald added a project: All.
aleksandr.popov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add test case when we widen condition to the branch which was previously
widened itself. We turn this branch from loop invariant into loop
variant one and cause issue similar to
https://github.com/llvm/llvm-project/issues/60234


https://reviews.llvm.org/D155473

Files:
  llvm/test/Transforms/GuardWidening/eliminated-branch-not-insert-point.ll


Index: llvm/test/Transforms/GuardWidening/eliminated-branch-not-insert-point.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GuardWidening/eliminated-branch-not-insert-point.ll
@@ -0,0 +1,67 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -S -passes=guard-widening < %s | FileCheck %s
+
+; TODO: Fix incorrect insertion point
+; - firstly we widen 'br i1 %exiplicit_guard_cond1' into 'br i1 %wc0'
+; and turn it into 'br i1 true';
+; - then we widen 'br i1 %exiplicit_guard_cond2' into 'br i1 true',
+; which is still considered as a guard;
+; - thus 'br i1 true' becomes an insertion point for the condition
+; and it's incorrect because we turn loop invariant branch into loop
+; variant one.
+define i64 @test(ptr addrspace(1) %0, i64 %1, i32 %2) {
+; CHECK-LABEL: define i64 @test
+; CHECK-SAME: (ptr addrspace(1) [[TMP0:%.*]], i64 [[TMP1:%.*]], i32 [[TMP2:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DOTGW_FR:%.*]] = freeze i32 [[TMP2]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[DOTGW_FR]], 0
+; CHECK-NEXT:    [[WIDE_CHK:%.*]] = and i1 true, [[CMP]]
+; CHECK-NEXT:    [[WC0:%.*]] = call i1 @llvm.experimental.widenable.condition()
+; CHECK-NEXT:    [[TMP3:%.*]] = and i1 [[WIDE_CHK]], [[WC0]]
+; CHECK-NEXT:    br i1 [[TMP3]], label [[PREHEADER:%.*]], label [[DEOPT:%.*]]
+; CHECK:       preheader:
+; CHECK-NEXT:    [[WC1:%.*]] = call i1 @llvm.experimental.widenable.condition()
+; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND1:%.*]] = and i1 [[CMP]], [[WC1]]
+; CHECK-NEXT:    br label [[LOOP_HEADER:%.*]]
+; CHECK:       loop.header:
+; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[PREHEADER]] ], [ [[IV_NEXT:%.*]], [[LOOP_BODY:%.*]] ]
+; CHECK-NEXT:    [[CMP_IV:%.*]] = icmp ult i32 [[IV]], 100
+; CHECK-NEXT:    [[WIDE_CHK1:%.*]] = and i1 true, [[CMP_IV]]
+; CHECK-NEXT:    br i1 [[WIDE_CHK1]], label [[LOOP_BODY]], label [[DEOPT]]
+; CHECK:       loop.body:
+; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], 1
+; CHECK-NEXT:    [[WC2:%.*]] = call i1 @llvm.experimental.widenable.condition()
+; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND2:%.*]] = and i1 [[CMP_IV]], [[WC2]]
+; CHECK-NEXT:    br i1 true, label [[LOOP_HEADER]], label [[DEOPT]]
+; CHECK:       deopt:
+; CHECK-NEXT:    [[DEOPTCALL:%.*]] = call i64 (...) @llvm.experimental.deoptimize.i64() [ "deopt"() ]
+; CHECK-NEXT:    ret i64 [[DEOPTCALL]]
+;
+entry:
+  %wc0 = call i1 @llvm.experimental.widenable.condition()
+  br i1 %wc0, label %preheader, label %deopt
+
+preheader:
+  %cmp = icmp eq i32 %2, 0
+  %wc1 = call i1 @llvm.experimental.widenable.condition()
+  %exiplicit_guard_cond1 = and i1 %cmp, %wc1
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %preheader ], [ %iv.next, %loop.body ]
+  br i1 %exiplicit_guard_cond1, label %loop.body, label %deopt
+
+loop.body:
+  %iv.next = add nuw nsw i32 %iv, 1
+  %cmp.iv = icmp ult i32 %iv, 100
+  %wc2 = call i1 @llvm.experimental.widenable.condition()
+  %exiplicit_guard_cond2 = and i1 %cmp.iv, %wc2
+  br i1 %exiplicit_guard_cond2, label %loop.header, label %deopt
+
+deopt:
+  %deoptcall = call i64 (...) @llvm.experimental.deoptimize.i64() [ "deopt"() ]
+  ret i64 %deoptcall
+}
+
+declare i1 @llvm.experimental.widenable.condition()
+declare i64 @llvm.experimental.deoptimize.i64(...)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155473.541058.patch
Type: text/x-patch
Size: 3354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230717/a837037c/attachment.bin>


More information about the llvm-commits mailing list