1; RUN: opt < %s -reassociate -constprop -instcombine -dce -S | FileCheck %s 2 3; With sub reassociation, constant folding can eliminate all of the constants. 4define i32 @test1(i32 %A, i32 %B) { 5; CHECK-LABEL: test1 6; CHECK-NEXT: %Z = sub i32 %A, %B 7; CHECK-NEXT: ret i32 %Z 8 9 %W = add i32 5, %B 10 %X = add i32 -7, %A 11 %Y = sub i32 %X, %W 12 %Z = add i32 %Y, 12 13 ret i32 %Z 14} 15 16; With sub reassociation, constant folding can eliminate the two 12 constants. 17define i32 @test2(i32 %A, i32 %B, i32 %C, i32 %D) { 18; CHECK-LABEL: test2 19; CHECK-NEXT: %sum = add i32 %B, %A 20; CHECK-NEXT: %sum1 = add i32 %sum, %C 21; CHECK-NEXT: %Q = sub i32 %D, %sum1 22; CHECK-NEXT: ret i32 %Q 23 24 %M = add i32 %A, 12 25 %N = add i32 %M, %B 26 %O = add i32 %N, %C 27 %P = sub i32 %D, %O 28 %Q = add i32 %P, 12 29 ret i32 %Q 30} 31