mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-19 02:25:01 +00:00
InstCombine: Optimize x/INT_MIN to x==INT_MIN
The result of x/INT_MIN is either 0 or 1, we can just use an icmp instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212167 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -993,6 +993,10 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Constant *RHS = dyn_cast<Constant>(Op1)) {
|
if (Constant *RHS = dyn_cast<Constant>(Op1)) {
|
||||||
|
// X/INT_MIN -> X == INT_MIN
|
||||||
|
if (RHS->isMinSignedValue())
|
||||||
|
return new ZExtInst(Builder->CreateICmpEQ(Op0, Op1), I.getType());
|
||||||
|
|
||||||
// -X/C --> X/-C provided the negation doesn't overflow.
|
// -X/C --> X/-C provided the negation doesn't overflow.
|
||||||
if (SubOperator *Sub = dyn_cast<SubOperator>(Op0))
|
if (SubOperator *Sub = dyn_cast<SubOperator>(Op0))
|
||||||
if (match(Sub->getOperand(0), m_Zero()) && Sub->hasNoSignedWrap())
|
if (match(Sub->getOperand(0), m_Zero()) && Sub->hasNoSignedWrap())
|
||||||
|
@@ -450,9 +450,9 @@ define <2 x i32> @test37(<2 x i32> %A) {
|
|||||||
%sub = sub nsw <2 x i32> zeroinitializer, %div
|
%sub = sub nsw <2 x i32> zeroinitializer, %div
|
||||||
ret <2 x i32> %sub
|
ret <2 x i32> %sub
|
||||||
; CHECK-LABEL: @test37(
|
; CHECK-LABEL: @test37(
|
||||||
; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> %A, <i32 -2147483648, i32 -2147483648>
|
; CHECK-NEXT: [[ICMP:%.*]] = icmp eq <2 x i32> %A, <i32 -2147483648, i32 -2147483648>
|
||||||
; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %div
|
; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[ICMP]] to <2 x i32>
|
||||||
; CHECK-NEXT: ret <2 x i32> [[SUB]]
|
; CHECK-NEXT: ret <2 x i32> [[SEXT]]
|
||||||
}
|
}
|
||||||
|
|
||||||
define i32 @test38(i32 %A) {
|
define i32 @test38(i32 %A) {
|
||||||
@@ -460,7 +460,7 @@ define i32 @test38(i32 %A) {
|
|||||||
%sub = sub nsw i32 0, %div
|
%sub = sub nsw i32 0, %div
|
||||||
ret i32 %sub
|
ret i32 %sub
|
||||||
; CHECK-LABEL: @test38(
|
; CHECK-LABEL: @test38(
|
||||||
; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 %A, -2147483648
|
; CHECK-NEXT: [[ICMP:%.*]] = icmp eq i32 %A, -2147483648
|
||||||
; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[DIV]]
|
; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[ICMP]] to i32
|
||||||
; CHECK-NEXT: ret i32 [[SUB]]
|
; CHECK-NEXT: ret i32 [[SEXT]]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user