1; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s 2 3; With sub reassociation, constant folding can eliminate the 12 and -12 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 %X = add i32 -12, %A 10 %Y = sub i32 %X, %B 11 %Z = add i32 %Y, 12 12 ret i32 %Z 13} 14 15; PR2047 16; With sub reassociation, constant folding can eliminate the uses of %a. 17define i32 @test2(i32 %a, i32 %b, i32 %c) { 18; CHECK-LABEL: @test2( 19; CHECK-NEXT: [[SUM:%.*]] = add i32 %c, %b 20; CHECK-NEXT: [[TMP7:%.*]] = sub i32 0, [[SUM]] 21; CHECK-NEXT: ret i32 [[TMP7]] 22; 23 %tmp3 = sub i32 %a, %b 24 %tmp5 = sub i32 %tmp3, %c 25 %tmp7 = sub i32 %tmp5, %a 26 ret i32 %tmp7 27} 28 29