[llvm] ab4e1be - [InstCombine] Add a test for folding freeze into phi; NFC

Juneyoung Lee via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 26 10:26:50 PDT 2020


Author: Juneyoung Lee
Date: 2020-07-27T02:24:00+09:00
New Revision: ab4e1be7ab3f1a1e7b78316b5b1929963e0e3bce

URL: https://github.com/llvm/llvm-project/commit/ab4e1be7ab3f1a1e7b78316b5b1929963e0e3bce
DIFF: https://github.com/llvm/llvm-project/commit/ab4e1be7ab3f1a1e7b78316b5b1929963e0e3bce.diff

LOG: [InstCombine] Add a test for folding freeze into phi; NFC

Added: 
    llvm/test/Transforms/InstCombine/freeze-phi.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/freeze-phi.ll b/llvm/test/Transforms/InstCombine/freeze-phi.ll
new file mode 100644
index 000000000000..fcda502a0d7f
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/freeze-phi.ll
@@ -0,0 +1,171 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @const(i1 %cond) {
+; CHECK-LABEL: @const(
+; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
+; CHECK:       A:
+; CHECK-NEXT:    br label [[C:%.*]]
+; CHECK:       B:
+; CHECK-NEXT:    br label [[C]]
+; CHECK:       C:
+; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ 1, [[B]] ]
+; CHECK-NEXT:    ret i32 [[Y]]
+;
+  br i1 %cond, label %A, label %B
+A:
+  br label %C
+B:
+  br label %C
+C:
+  %y = phi i32 [0, %A], [1, %B]
+  %y.fr = freeze i32 %y
+  ret i32 %y
+}
+
+define i32 @one(i1 %cond, i32 %x) {
+; CHECK-LABEL: @one(
+; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
+; CHECK:       A:
+; CHECK-NEXT:    br label [[C:%.*]]
+; CHECK:       B:
+; CHECK-NEXT:    br label [[C]]
+; CHECK:       C:
+; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ [[X:%.*]], [[B]] ]
+; CHECK-NEXT:    [[Y_FR:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[Y_FR]]
+;
+  br i1 %cond, label %A, label %B
+A:
+  br label %C
+B:
+  br label %C
+C:
+  %y = phi i32 [0, %A], [%x, %B]
+  %y.fr = freeze i32 %y
+  ret i32 %y.fr
+}
+
+define i32 @two(i1 %cond, i32 %x, i32 %x2) {
+; CHECK-LABEL: @two(
+; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
+; CHECK:       A:
+; CHECK-NEXT:    br label [[C:%.*]]
+; CHECK:       B:
+; CHECK-NEXT:    br label [[C]]
+; CHECK:       C:
+; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ [[X:%.*]], [[A]] ], [ [[X2:%.*]], [[B]] ]
+; CHECK-NEXT:    [[Y_FR:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[Y_FR]]
+;
+  br i1 %cond, label %A, label %B
+A:
+  br label %C
+B:
+  br label %C
+C:
+  %y = phi i32 [%x, %A], [%x2, %B]
+  %y.fr = freeze i32 %y
+  ret i32 %y.fr
+}
+
+define i32 @two_undef(i8 %cond, i32 %x) {
+; CHECK-LABEL: @two_undef(
+; CHECK-NEXT:    switch i8 [[COND:%.*]], label [[A:%.*]] [
+; CHECK-NEXT:    i8 0, label [[B:%.*]]
+; CHECK-NEXT:    i8 1, label [[C:%.*]]
+; CHECK-NEXT:    ]
+; CHECK:       A:
+; CHECK-NEXT:    br label [[D:%.*]]
+; CHECK:       B:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       C:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       D:
+; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ undef, [[A]] ], [ [[X:%.*]], [[B]] ], [ 0, [[C]] ]
+; CHECK-NEXT:    [[Y_FR:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[Y_FR]]
+;
+  switch i8 %cond, label %A [
+  i8 0, label %B
+  i8 1, label %C
+  ]
+A:
+  br label %D
+B:
+  br label %D
+C:
+  br label %D
+D:
+  %y = phi i32 [undef, %A], [%x, %B], [0, %C]
+  %y.fr = freeze i32 %y
+  ret i32 %y.fr
+}
+
+define i32 @one_undef(i8 %cond) {
+; CHECK-LABEL: @one_undef(
+; CHECK-NEXT:    switch i8 [[COND:%.*]], label [[A:%.*]] [
+; CHECK-NEXT:    i8 0, label [[B:%.*]]
+; CHECK-NEXT:    i8 1, label [[C:%.*]]
+; CHECK-NEXT:    ]
+; CHECK:       A:
+; CHECK-NEXT:    br label [[D:%.*]]
+; CHECK:       B:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       C:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       D:
+; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ undef, [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
+; CHECK-NEXT:    [[Y_FR:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[Y_FR]]
+;
+  switch i8 %cond, label %A [
+  i8 0, label %B
+  i8 1, label %C
+  ]
+A:
+  br label %D
+B:
+  br label %D
+C:
+  br label %D
+D:
+  %y = phi i32 [undef, %A], [32, %B], [0, %C]
+  %y.fr = freeze i32 %y
+  ret i32 %y.fr
+}
+
+ at glb = global i8 0
+
+define i32 @one_constexpr(i8 %cond, i32 %x) {
+; CHECK-LABEL: @one_constexpr(
+; CHECK-NEXT:    switch i8 [[COND:%.*]], label [[A:%.*]] [
+; CHECK-NEXT:    i8 0, label [[B:%.*]]
+; CHECK-NEXT:    i8 1, label [[C:%.*]]
+; CHECK-NEXT:    ]
+; CHECK:       A:
+; CHECK-NEXT:    br label [[D:%.*]]
+; CHECK:       B:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       C:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       D:
+; CHECK-NEXT:    [[Y:%.*]] = phi i32 [ ptrtoint (i8* getelementptr inbounds (i8, i8* @glb, i64 2) to i32), [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
+; CHECK-NEXT:    [[Y_FR:%.*]] = freeze i32 [[Y]]
+; CHECK-NEXT:    ret i32 [[Y_FR]]
+;
+  switch i8 %cond, label %A [
+  i8 0, label %B
+  i8 1, label %C
+  ]
+A:
+  br label %D
+B:
+  br label %D
+C:
+  br label %D
+D:
+  %y = phi i32 [ptrtoint (i8* getelementptr inbounds (i8, i8* @glb, i64 2) to i32), %A], [32, %B], [0, %C]
+  %y.fr = freeze i32 %y
+  ret i32 %y.fr
+}


        


More information about the llvm-commits mailing list