104 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2;3; Test cases in this file are intended to be run with both reassociate and4; gvn passes enabled.5;6; Test numbering remains continuous across:7; - InstCombine/fast-basictest.ll8; - PhaseOrdering/fast-basictest.ll9; - PhaseOrdering/fast-reassociate-gvn.ll10; - Reassociate/fast-basictest.ll11;12; RUN: opt < %s -passes=reassociate,gvn -S | FileCheck %s --check-prefixes=CHECK,REASSOC_AND_GVN --allow-unused-prefixes13; RUN: opt < %s -O2 -S | FileCheck %s --check-prefixes=CHECK,O2 --allow-unused-prefixes14 15@fe = external global float16@fa = external global float17@fb = external global float18@fc = external global float19@ff = external global float20 21; If two sums of the same operands in different order are counted with 'fast'22; flag and then stored to global variables, we can reuse the same value twice.23; Sums:24; - test3: (a+b)+c and (a+c)+b25; - test4: c+(a+b) and (c+a)+b26; - test5: c+(b+a) and (c+a)+b27; TODO: check if 'reassoc' flag is technically enough for this optimization28; (currently the transformation is not done with 'reassoc' only).29 30define void @test3() {31; CHECK-LABEL: @test3(32; CHECK-NEXT: [[A:%.*]] = load float, ptr @fa, align 433; CHECK-NEXT: [[B:%.*]] = load float, ptr @fb, align 434; CHECK-NEXT: [[C:%.*]] = load float, ptr @fc, align 435; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]36; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]37; CHECK-NEXT: store float [[T2]], ptr @fe, align 438; CHECK-NEXT: store float [[T2]], ptr @ff, align 439; CHECK-NEXT: ret void40;41 %A = load float, ptr @fa42 %B = load float, ptr @fb43 %C = load float, ptr @fc44 %t1 = fadd fast float %A, %B45 %t2 = fadd fast float %t1, %C46 %t3 = fadd fast float %A, %C47 %t4 = fadd fast float %t3, %B48 ; e = (a+b)+c;49 store float %t2, ptr @fe50 ; f = (a+c)+b51 store float %t4, ptr @ff52 ret void53}54 55define void @test4() {56; CHECK-LABEL: @test4(57; CHECK-NEXT: [[A:%.*]] = load float, ptr @fa, align 458; CHECK-NEXT: [[B:%.*]] = load float, ptr @fb, align 459; CHECK-NEXT: [[C:%.*]] = load float, ptr @fc, align 460; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]61; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]62; CHECK-NEXT: store float [[T2]], ptr @fe, align 463; CHECK-NEXT: store float [[T2]], ptr @ff, align 464; CHECK-NEXT: ret void65;66 %A = load float, ptr @fa67 %B = load float, ptr @fb68 %C = load float, ptr @fc69 %t1 = fadd fast float %A, %B70 %t2 = fadd fast float %C, %t171 %t3 = fadd fast float %C, %A72 %t4 = fadd fast float %t3, %B73 ; e = c+(a+b)74 store float %t2, ptr @fe75 ; f = (c+a)+b76 store float %t4, ptr @ff77 ret void78}79 80define void @test5() {81; CHECK-LABEL: @test5(82; CHECK-NEXT: [[A:%.*]] = load float, ptr @fa, align 483; CHECK-NEXT: [[B:%.*]] = load float, ptr @fb, align 484; CHECK-NEXT: [[C:%.*]] = load float, ptr @fc, align 485; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]86; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]87; CHECK-NEXT: store float [[T2]], ptr @fe, align 488; CHECK-NEXT: store float [[T2]], ptr @ff, align 489; CHECK-NEXT: ret void90;91 %A = load float, ptr @fa92 %B = load float, ptr @fb93 %C = load float, ptr @fc94 %t1 = fadd fast float %B, %A95 %t2 = fadd fast float %C, %t196 %t3 = fadd fast float %C, %A97 %t4 = fadd fast float %t3, %B98 ; e = c+(b+a)99 store float %t2, ptr @fe100 ; f = (c+a)+b101 store float %t4, ptr @ff102 ret void103}104