From 726901b638a4f791b565bae9f1cdc396e17736ca Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 23 Jun 2015 02:49:24 +0000 Subject: [InstCombine] Optimize subtract of selects into a select of a sub This came up when examining some code generated by clang's IRGen for certain member pointers. llvm-svn: 240369 --- llvm/test/Transforms/InstCombine/sub.ll | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'llvm/test/Transforms/InstCombine/sub.ll') diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll index c76d8d0e220..b1c7b7245cf 100644 --- a/llvm/test/Transforms/InstCombine/sub.ll +++ b/llvm/test/Transforms/InstCombine/sub.ll @@ -550,3 +550,25 @@ define i32 @test46(i32 %x, i32 %y) { ; CHECK-NEXT: %sub = and i32 %y, %x.not ; CHECK: ret i32 %sub } + +define i32 @test47(i1 %A, i32 %B, i32 %C, i32 %D) { + %sel0 = select i1 %A, i32 %D, i32 %B + %sel1 = select i1 %A, i32 %C, i32 %B + %sub = sub i32 %sel0, %sel1 + ret i32 %sub +; CHECK-LABEL: @test47( +; CHECK-NEXT: %[[sub:.*]] = sub i32 %D, %C +; CHECK-NEXT: %[[sel:.*]] = select i1 %A, i32 %[[sub]], i32 0 +; CHECK-NEXT: ret i32 %[[sel]] +} + +define i32 @test48(i1 %A, i32 %B, i32 %C, i32 %D) { + %sel0 = select i1 %A, i32 %B, i32 %D + %sel1 = select i1 %A, i32 %B, i32 %C + %sub = sub i32 %sel0, %sel1 + ret i32 %sub +; CHECK-LABEL: @test48( +; CHECK-NEXT: %[[sub:.*]] = sub i32 %D, %C +; CHECK-NEXT: %[[sel:.*]] = select i1 %A, i32 0, i32 %[[sub]] +; CHECK-NEXT: ret i32 %[[sel]] +} -- cgit v1.2.3