[llvm] ea24948 - [Test][AggressiveInstCombine] Add test for `phi` instruction
Anton Afanasyev via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 23 01:52:23 PST 2022
Author: Anton Afanasyev
Date: 2022-02-23T12:50:50+03:00
New Revision: ea249489f5f5c770475587010833b8c3ecb581e7
URL: https://github.com/llvm/llvm-project/commit/ea249489f5f5c770475587010833b8c3ecb581e7
DIFF: https://github.com/llvm/llvm-project/commit/ea249489f5f5c770475587010833b8c3ecb581e7.diff
LOG: [Test][AggressiveInstCombine] Add test for `phi` instruction
Added:
llvm/test/Transforms/AggressiveInstCombine/trunc_phi.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/AggressiveInstCombine/trunc_phi.ll b/llvm/test/Transforms/AggressiveInstCombine/trunc_phi.ll
new file mode 100644
index 0000000000000..46bdb60fada6c
--- /dev/null
+++ b/llvm/test/Transforms/AggressiveInstCombine/trunc_phi.ll
@@ -0,0 +1,74 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -aggressive-instcombine -S | FileCheck %s
+
+define i16 @trunc_phi(i8 %x) {
+; CHECK-LABEL: @trunc_phi(
+; CHECK-NEXT: LoopHeader:
+; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[X:%.*]] to i32
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: Loop:
+; CHECK-NEXT: [[ZEXT2:%.*]] = phi i32 [ [[ZEXT]], [[LOOPHEADER:%.*]] ], [ [[SHL:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[LOOPHEADER]] ], [ [[I:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[SHL]] = shl i32 [[ZEXT2]], 1
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[SHL]] to i16
+; CHECK-NEXT: [[I]] = add i32 [[J]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I]], 10
+; CHECK-NEXT: br i1 [[CMP]], label [[LOOPEND:%.*]], label [[LOOP]]
+; CHECK: LoopEnd:
+; CHECK-NEXT: ret i16 [[TRUNC]]
+;
+LoopHeader:
+ %zext = zext i8 %x to i32
+ br label %Loop
+
+Loop:
+ %zext2 = phi i32 [%zext, %LoopHeader], [%shl, %Loop]
+ %j = phi i32 [0, %LoopHeader], [%i, %Loop]
+ %shl = shl i32 %zext2, 1
+ %trunc = trunc i32 %shl to i16
+ %i = add i32 %j, 1
+ %cmp = icmp eq i32 %i, 10
+ br i1 %cmp, label %LoopEnd, label %Loop
+
+LoopEnd:
+ ret i16 %trunc
+}
+
+define i16 @trunc_phi2(i8 %x, i32 %sw) {
+; CHECK-LABEL: @trunc_phi2(
+; CHECK-NEXT: LoopHeader:
+; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[X:%.*]] to i32
+; CHECK-NEXT: switch i32 [[SW:%.*]], label [[LOOPEND:%.*]] [
+; CHECK-NEXT: i32 0, label [[LOOP:%.*]]
+; CHECK-NEXT: i32 1, label [[LOOP]]
+; CHECK-NEXT: ]
+; CHECK: Loop:
+; CHECK-NEXT: [[ZEXT2:%.*]] = phi i32 [ [[ZEXT]], [[LOOPHEADER:%.*]] ], [ [[ZEXT]], [[LOOPHEADER]] ], [ [[SHL:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[LOOPHEADER]] ], [ 0, [[LOOPHEADER]] ], [ [[I:%.*]], [[LOOP]] ]
+; CHECK-NEXT: [[SHL]] = shl i32 [[ZEXT2]], 1
+; CHECK-NEXT: [[I]] = add i32 [[J]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I]], 10
+; CHECK-NEXT: br i1 [[CMP]], label [[LOOPEND]], label [[LOOP]]
+; CHECK: LoopEnd:
+; CHECK-NEXT: [[ZEXT3:%.*]] = phi i32 [ [[ZEXT]], [[LOOPHEADER]] ], [ [[ZEXT2]], [[LOOP]] ]
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[ZEXT3]] to i16
+; CHECK-NEXT: ret i16 [[TRUNC]]
+;
+LoopHeader:
+ %zext = zext i8 %x to i32
+ switch i32 %sw, label %LoopEnd [ i32 0, label %Loop
+ i32 1, label %Loop ]
+
+Loop:
+ %zext2 = phi i32 [%zext, %LoopHeader], [%zext, %LoopHeader], [%shl, %Loop]
+ %j = phi i32 [0, %LoopHeader], [0, %LoopHeader], [%i, %Loop]
+ %shl = shl i32 %zext2, 1
+ %i = add i32 %j, 1
+ %cmp = icmp eq i32 %i, 10
+ br i1 %cmp, label %LoopEnd, label %Loop
+
+LoopEnd:
+ %zext3 = phi i32 [%zext, %LoopHeader], [%zext2, %Loop]
+ %trunc = trunc i32 %zext3 to i16
+ ret i16 %trunc
+}
More information about the llvm-commits
mailing list