From 171825a8cec198cad76ed9c032f537fd42e78325 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 11 Oct 2014 10:20:04 +0000 Subject: [PATCH] InstCombine: Don't fold (X <getBitWidth() - 1) || (!IsSigned && match(LHS, m_NUWShl(m_Value(X), m_APInt(C1))))) { APInt Quotient(C1->getBitWidth(), /*Val=*/0ULL, IsSigned); APInt C1Shifted = APInt::getOneBitSet( diff --git a/test/Transforms/InstCombine/div.ll b/test/Transforms/InstCombine/div.ll index 26e9e336823..5a884ac671d 100644 --- a/test/Transforms/InstCombine/div.ll +++ b/test/Transforms/InstCombine/div.ll @@ -247,3 +247,20 @@ define i32 @test28(i32 %a) { ; CHECK-NEXT: %div = mul nuw i32 %a, 12 ; CHECK-NEXT: ret i32 %div } + +define i32 @test29(i32 %a) { + %mul = shl nsw i32 %a, 31 + %div = sdiv i32 %mul, -2147483648 + ret i32 %div +; CHECK-LABEL: @test29( +; CHECK-NEXT: %[[and:.*]] = and i32 %a, 1 +; CHECK-NEXT: ret i32 %[[and]] +} + +define i32 @test30(i32 %a) { + %mul = shl nuw i32 %a, 31 + %div = udiv i32 %mul, -2147483648 + ret i32 %div +; CHECK-LABEL: @test30( +; CHECK-NEXT: ret i32 %a +}