635 changes: 635 additions & 0 deletions llvm/lib/Transforms/Utils/IRCanonicalizer.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions llvm/lib/Transforms/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void llvm::initializeTransformUtils(PassRegistry &Registry) {
initializeCanonicalizeAliasesLegacyPassPass(Registry);
initializeCanonicalizeFreezeInLoopsPass(Registry);
initializeInstNamerPass(Registry);
initializeIRCanonicalizerPass(Registry);
initializeLCSSAWrapperPassPass(Registry);
initializeLibCallsShrinkWrapLegacyPassPass(Registry);
initializeLoopSimplifyPass(Registry);
Expand Down
7 changes: 7 additions & 0 deletions llvm/test/Transforms/IRCanonicalizer/naming-arguments.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; RUN: opt -S --ir-canonicalizer < %s | FileCheck %s

; CHECK: @foo(i32 %a0, i32 %a1)
define i32 @foo(i32, i32) {
%tmp = mul i32 %0, %1
ret i32 %tmp
}
8 changes: 8 additions & 0 deletions llvm/test/Transforms/IRCanonicalizer/naming-basic-blocks.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; RUN: opt -S --ir-canonicalizer --rename-all < %s | FileCheck %s

define i32 @foo(i32 %a0) {
; CHECK: bb{{([0-9]{5})}}
entry:
%a = add i32 %a0, 2
ret i32 %a
}
12 changes: 12 additions & 0 deletions llvm/test/Transforms/IRCanonicalizer/naming-instructions.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; RUN: opt -S --ir-canonicalizer --rename-all < %s | FileCheck %s

define i32 @foo(i32 %a0) {
entry:
; CHECK: %"vl{{([0-9]{5})}}(%a0, 2)"
%a = add i32 %a0, 2
; CHECK: %"op{{([0-9]{5})}}(vl{{([0-9]{5})}})"
%b = add i32 %a, 6
; CHECK: %"op{{([0-9]{5})}}(8, op{{([0-9]{5})}}(6, vl{{([0-9]{5})}}(%a0, 2)))"
%c = add i32 %b, 8
ret i32 %c
}
14 changes: 14 additions & 0 deletions llvm/test/Transforms/IRCanonicalizer/reordering-instructions.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: opt -S --ir-canonicalizer < %s | FileCheck %s

define double @foo(double %a0, double %a1) {
entry:
; CHECK: %a
; CHECK: %c
; CHECK: %b
; CHECK: %d
%a = fmul double %a0, %a1
%b = fmul double %a0, 2.000000e+00
%c = fmul double %a, 6.000000e+00
%d = fmul double %b, 6.000000e+00
ret double %d
}
24 changes: 24 additions & 0 deletions llvm/test/Transforms/IRCanonicalizer/reordering-phi-node-values.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: opt -S --ir-canonicalizer < %s | FileCheck %s

declare double @foo()

declare double @bar()

define double @baz(double %x) {
entry:
%ifcond = fcmp one double %x, 0.000000e+00
br i1 %ifcond, label %then, label %else

then: ; preds = %entry
%calltmp = call double @foo()
br label %ifcont

else: ; preds = %entry
%calltmp1 = call double @bar()
br label %ifcont

ifcont: ; preds = %else, %then
; CHECK: %iftmp = phi double [ %calltmp1, %else ], [ %calltmp, %then ]
%iftmp = phi double [ %calltmp, %then ], [ %calltmp1, %else ]
ret double %iftmp
}