[PATCH] D156458: GVNSink: add test to show GVN-aware sinking
Ramkumar Ramachandra via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 04:35:15 PDT 2023
artagnon updated this revision to Diff 545101.
artagnon added a comment.
Address review comment; run test through opt pipeline until gvn-sink.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156458/new/
https://reviews.llvm.org/D156458
Files:
llvm/test/Transforms/GVNSink/gvn-awareness.ll
Index: llvm/test/Transforms/GVNSink/gvn-awareness.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GVNSink/gvn-awareness.ll
@@ -0,0 +1,65 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; Test to show a sinking operation that would have been impossible without
+; GVN-awareness.
+; RUN: opt -passes=gvn-sink -S < %s | FileCheck %s
+
+define void @gvn_awareness(ptr nocapture writeonly %a, i32 %beam) {
+; CHECK-LABEL: define void @gvn_awareness
+; CHECK-SAME: (ptr nocapture writeonly [[A:%.*]], i32 [[BEAM:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[FOR_COND:%.*]]
+; CHECK: for.cond:
+; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I_0]], 10000
+; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]]
+; CHECK: for.cond.cleanup:
+; CHECK-NEXT: ret void
+; CHECK: for.body:
+; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[I_0]], [[BEAM]]
+; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: br label [[FOR_INC]]
+; CHECK: if.else:
+; CHECK-NEXT: br label [[FOR_INC]]
+; CHECK: for.inc:
+; CHECK-NEXT: [[DOTSINK:%.*]] = phi i32 [ 0, [[IF_THEN]] ], [ 1, [[IF_ELSE]] ]
+; CHECK-NEXT: [[MUL:%.*]] = shl nuw nsw i32 [[I_0]], 1
+; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[MUL]] to i64
+; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IDXPROM]]
+; CHECK-NEXT: store i32 [[DOTSINK]], ptr [[ARRAYIDX]], align 4
+; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_0]], 1
+; CHECK-NEXT: br label [[FOR_COND]]
+;
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
+ %cmp = icmp ult i32 %i.0, 10000
+ br i1 %cmp, label %for.body, label %for.cond.cleanup
+
+for.cond.cleanup: ; preds = %for.cond
+ ret void
+
+for.body: ; preds = %for.cond
+ %cmp1 = icmp eq i32 %i.0, %beam
+ br i1 %cmp1, label %if.then, label %if.else
+
+if.then: ; preds = %for.body
+ %mul = shl nuw nsw i32 %i.0, 1
+ %idxprom = zext i32 %mul to i64
+ %arrayidx = getelementptr inbounds i32, ptr %a, i64 %idxprom
+ store i32 0, ptr %arrayidx, align 4
+ br label %for.inc
+
+if.else: ; preds = %for.body
+ %mul2 = shl nuw nsw i32 %i.0, 1
+ %idxprom3 = zext i32 %mul2 to i64
+ %arrayidx4 = getelementptr inbounds i32, ptr %a, i64 %idxprom3
+ store i32 1, ptr %arrayidx4, align 4
+ br label %for.inc
+
+for.inc: ; preds = %if.then, %if.else
+ %inc = add nuw nsw i32 %i.0, 1
+ br label %for.cond
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156458.545101.patch
Type: text/x-patch
Size: 2979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230728/e6876657/attachment.bin>
More information about the llvm-commits
mailing list