1 ; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s 2 3 define float @test1(float %A, float %B) { 4 ; CHECK-LABEL: @test1( 5 ; CHECK-NEXT: [[Z:%.*]] = fadd fast float %A, %B 6 ; CHECK-NEXT: ret float [[Z]] 7 ; 8 %W = fadd fast float %B, -5.0 9 %Y = fadd fast float %A, 5.0 10 %Z = fadd fast float %W, %Y 11 ret float %Z 12 } 13 14 ; Check again using minimal subset of FMF. 15 ; Both 'reassoc' and 'nsz' are required. 16 define float @test1_reassoc_nsz(float %A, float %B) { 17 ; CHECK-LABEL: @test1_reassoc_nsz( 18 ; CHECK-NEXT: [[Z:%.*]] = fadd reassoc nsz float %A, %B 19 ; CHECK-NEXT: ret float [[Z]] 20 ; 21 %W = fadd reassoc nsz float %B, -5.0 22 %Y = fadd reassoc nsz float %A, 5.0 23 %Z = fadd reassoc nsz float %W, %Y 24 ret float %Z 25 } 26 27 ; Verify the fold is not done with only 'reassoc' ('nsz' is required). 28 define float @test1_reassoc(float %A, float %B) { 29 ; CHECK-LABEL: @test1_reassoc( 30 ; CHECK-NEXT: [[W:%.*]] = fadd reassoc float %B, -5.000000e+00 31 ; CHECK-NEXT: [[Y:%.*]] = fadd reassoc float %A, 5.000000e+00 32 ; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[Y]], [[W]] 33 ; CHECK-NEXT: ret float [[Z]] 34 ; 35 %W = fadd reassoc float %B, -5.0 36 %Y = fadd reassoc float %A, 5.0 37 %Z = fadd reassoc float %W, %Y 38 ret float %Z 39 } 40