mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-25 16:29:20 +00:00
Revert r206045, "Fix shift by constants for vector."
It broke some builders, at least, i686. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206153 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1907f75445
commit
9854380054
@ -171,7 +171,7 @@ public:
|
|||||||
ICmpInst::Predicate Pred);
|
ICmpInst::Predicate Pred);
|
||||||
Instruction *FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
|
Instruction *FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
|
||||||
ICmpInst::Predicate Cond, Instruction &I);
|
ICmpInst::Predicate Cond, Instruction &I);
|
||||||
Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1,
|
Instruction *FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||||
BinaryOperator &I);
|
BinaryOperator &I);
|
||||||
Instruction *commonCastTransforms(CastInst &CI);
|
Instruction *commonCastTransforms(CastInst &CI);
|
||||||
Instruction *commonPointerCastTransforms(CastInst &CI);
|
Instruction *commonPointerCastTransforms(CastInst &CI);
|
||||||
|
@ -33,7 +33,7 @@ Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) {
|
|||||||
if (Instruction *R = FoldOpIntoSelect(I, SI))
|
if (Instruction *R = FoldOpIntoSelect(I, SI))
|
||||||
return R;
|
return R;
|
||||||
|
|
||||||
if (Constant *CUI = dyn_cast<Constant>(Op1))
|
if (ConstantInt *CUI = dyn_cast<ConstantInt>(Op1))
|
||||||
if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))
|
if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))
|
||||||
return Res;
|
return Res;
|
||||||
|
|
||||||
@ -309,30 +309,20 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||||
BinaryOperator &I) {
|
BinaryOperator &I) {
|
||||||
bool isLeftShift = I.getOpcode() == Instruction::Shl;
|
bool isLeftShift = I.getOpcode() == Instruction::Shl;
|
||||||
|
|
||||||
ConstantInt *COp1 = nullptr;
|
|
||||||
if (ConstantDataVector *CV = dyn_cast<ConstantDataVector>(Op1))
|
|
||||||
COp1 = dyn_cast_or_null<ConstantInt>(CV->getSplatValue());
|
|
||||||
else if (ConstantVector *CV = dyn_cast<ConstantVector>(Op1))
|
|
||||||
COp1 = dyn_cast_or_null<ConstantInt>(CV->getSplatValue());
|
|
||||||
else
|
|
||||||
COp1 = dyn_cast<ConstantInt>(Op1);
|
|
||||||
|
|
||||||
if (!COp1)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// See if we can propagate this shift into the input, this covers the trivial
|
// See if we can propagate this shift into the input, this covers the trivial
|
||||||
// cast of lshr(shl(x,c1),c2) as well as other more complex cases.
|
// cast of lshr(shl(x,c1),c2) as well as other more complex cases.
|
||||||
if (I.getOpcode() != Instruction::AShr &&
|
if (I.getOpcode() != Instruction::AShr &&
|
||||||
CanEvaluateShifted(Op0, COp1->getZExtValue(), isLeftShift, *this)) {
|
CanEvaluateShifted(Op0, Op1->getZExtValue(), isLeftShift, *this)) {
|
||||||
DEBUG(dbgs() << "ICE: GetShiftedValue propagating shift through expression"
|
DEBUG(dbgs() << "ICE: GetShiftedValue propagating shift through expression"
|
||||||
" to eliminate shift:\n IN: " << *Op0 << "\n SH: " << I <<"\n");
|
" to eliminate shift:\n IN: " << *Op0 << "\n SH: " << I <<"\n");
|
||||||
|
|
||||||
return ReplaceInstUsesWith(I,
|
return ReplaceInstUsesWith(I,
|
||||||
GetShiftedValue(Op0, COp1->getZExtValue(), isLeftShift, *this));
|
GetShiftedValue(Op0, Op1->getZExtValue(), isLeftShift, *this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -343,7 +333,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
|||||||
// shl i32 X, 32 = 0 and srl i8 Y, 9 = 0, ... just don't eliminate
|
// shl i32 X, 32 = 0 and srl i8 Y, 9 = 0, ... just don't eliminate
|
||||||
// a signed shift.
|
// a signed shift.
|
||||||
//
|
//
|
||||||
if (COp1->uge(TypeBits)) {
|
if (Op1->uge(TypeBits)) {
|
||||||
if (I.getOpcode() != Instruction::AShr)
|
if (I.getOpcode() != Instruction::AShr)
|
||||||
return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType()));
|
return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType()));
|
||||||
// ashr i32 X, 32 --> ashr i32 X, 31
|
// ashr i32 X, 32 --> ashr i32 X, 31
|
||||||
@ -356,7 +346,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
|||||||
if (BO->getOpcode() == Instruction::Mul && isLeftShift)
|
if (BO->getOpcode() == Instruction::Mul && isLeftShift)
|
||||||
if (Constant *BOOp = dyn_cast<Constant>(BO->getOperand(1)))
|
if (Constant *BOOp = dyn_cast<Constant>(BO->getOperand(1)))
|
||||||
return BinaryOperator::CreateMul(BO->getOperand(0),
|
return BinaryOperator::CreateMul(BO->getOperand(0),
|
||||||
ConstantExpr::getShl(BOOp, COp1));
|
ConstantExpr::getShl(BOOp, Op1));
|
||||||
|
|
||||||
// Try to fold constant and into select arguments.
|
// Try to fold constant and into select arguments.
|
||||||
if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
|
if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
|
||||||
@ -377,7 +367,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
|||||||
if (TrOp && I.isLogicalShift() && TrOp->isShift() &&
|
if (TrOp && I.isLogicalShift() && TrOp->isShift() &&
|
||||||
isa<ConstantInt>(TrOp->getOperand(1))) {
|
isa<ConstantInt>(TrOp->getOperand(1))) {
|
||||||
// Okay, we'll do this xform. Make the shift of shift.
|
// Okay, we'll do this xform. Make the shift of shift.
|
||||||
Constant *ShAmt = ConstantExpr::getZExt(COp1, TrOp->getType());
|
Constant *ShAmt = ConstantExpr::getZExt(Op1, TrOp->getType());
|
||||||
// (shift2 (shift1 & 0x00FF), c2)
|
// (shift2 (shift1 & 0x00FF), c2)
|
||||||
Value *NSh = Builder->CreateBinOp(I.getOpcode(), TrOp, ShAmt,I.getName());
|
Value *NSh = Builder->CreateBinOp(I.getOpcode(), TrOp, ShAmt,I.getName());
|
||||||
|
|
||||||
@ -394,10 +384,10 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
|||||||
// shift. We know that it is a logical shift by a constant, so adjust the
|
// shift. We know that it is a logical shift by a constant, so adjust the
|
||||||
// mask as appropriate.
|
// mask as appropriate.
|
||||||
if (I.getOpcode() == Instruction::Shl)
|
if (I.getOpcode() == Instruction::Shl)
|
||||||
MaskV <<= COp1->getZExtValue();
|
MaskV <<= Op1->getZExtValue();
|
||||||
else {
|
else {
|
||||||
assert(I.getOpcode() == Instruction::LShr && "Unknown logical shift");
|
assert(I.getOpcode() == Instruction::LShr && "Unknown logical shift");
|
||||||
MaskV = MaskV.lshr(COp1->getZExtValue());
|
MaskV = MaskV.lshr(Op1->getZExtValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// shift1 & 0x00FF
|
// shift1 & 0x00FF
|
||||||
@ -431,7 +421,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
|||||||
// (X + (Y << C))
|
// (X + (Y << C))
|
||||||
Value *X = Builder->CreateBinOp(Op0BO->getOpcode(), YS, V1,
|
Value *X = Builder->CreateBinOp(Op0BO->getOpcode(), YS, V1,
|
||||||
Op0BO->getOperand(1)->getName());
|
Op0BO->getOperand(1)->getName());
|
||||||
uint32_t Op1Val = COp1->getLimitedValue(TypeBits);
|
uint32_t Op1Val = Op1->getLimitedValue(TypeBits);
|
||||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
||||||
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
||||||
}
|
}
|
||||||
@ -463,7 +453,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
|||||||
// (X + (Y << C))
|
// (X + (Y << C))
|
||||||
Value *X = Builder->CreateBinOp(Op0BO->getOpcode(), V1, YS,
|
Value *X = Builder->CreateBinOp(Op0BO->getOpcode(), V1, YS,
|
||||||
Op0BO->getOperand(0)->getName());
|
Op0BO->getOperand(0)->getName());
|
||||||
uint32_t Op1Val = COp1->getLimitedValue(TypeBits);
|
uint32_t Op1Val = Op1->getLimitedValue(TypeBits);
|
||||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
||||||
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
||||||
}
|
}
|
||||||
@ -551,7 +541,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
|
|||||||
|
|
||||||
ConstantInt *ShiftAmt1C = cast<ConstantInt>(ShiftOp->getOperand(1));
|
ConstantInt *ShiftAmt1C = cast<ConstantInt>(ShiftOp->getOperand(1));
|
||||||
uint32_t ShiftAmt1 = ShiftAmt1C->getLimitedValue(TypeBits);
|
uint32_t ShiftAmt1 = ShiftAmt1C->getLimitedValue(TypeBits);
|
||||||
uint32_t ShiftAmt2 = COp1->getLimitedValue(TypeBits);
|
uint32_t ShiftAmt2 = Op1->getLimitedValue(TypeBits);
|
||||||
assert(ShiftAmt2 != 0 && "Should have been simplified earlier");
|
assert(ShiftAmt2 != 0 && "Should have been simplified earlier");
|
||||||
if (ShiftAmt1 == 0) return 0; // Will be simplified in the future.
|
if (ShiftAmt1 == 0) return 0; // Will be simplified in the future.
|
||||||
Value *X = ShiftOp->getOperand(0);
|
Value *X = ShiftOp->getOperand(0);
|
||||||
|
@ -40,27 +40,6 @@ define i32 @test5(i32 %A) {
|
|||||||
ret i32 %B
|
ret i32 %B
|
||||||
}
|
}
|
||||||
|
|
||||||
define <4 x i32> @test5_splat_vector(<4 x i32> %A) {
|
|
||||||
; CHECK-LABEL: @test5_splat_vector(
|
|
||||||
; CHECK: ret <4 x i32> undef
|
|
||||||
%B = lshr <4 x i32> %A, <i32 32, i32 32, i32 32, i32 32> ;; shift all bits out
|
|
||||||
ret <4 x i32> %B
|
|
||||||
}
|
|
||||||
|
|
||||||
define <4 x i32> @test5_zero_vector(<4 x i32> %A) {
|
|
||||||
; CHECK-LABEL: @test5_zero_vector(
|
|
||||||
; CHECK-NEXT: ret <4 x i32> %A
|
|
||||||
%B = lshr <4 x i32> %A, zeroinitializer
|
|
||||||
ret <4 x i32> %B
|
|
||||||
}
|
|
||||||
|
|
||||||
define <4 x i32> @test5_non_splat_vector(<4 x i32> %A) {
|
|
||||||
; CHECK-LABEL: @test5_non_splat_vector(
|
|
||||||
; CHECK-NOT: ret <4 x i32> undef
|
|
||||||
%B = shl <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
|
|
||||||
ret <4 x i32> %B
|
|
||||||
}
|
|
||||||
|
|
||||||
define i32 @test5a(i32 %A) {
|
define i32 @test5a(i32 %A) {
|
||||||
; CHECK-LABEL: @test5a(
|
; CHECK-LABEL: @test5a(
|
||||||
; CHECK: ret i32 undef
|
; CHECK: ret i32 undef
|
||||||
@ -68,20 +47,6 @@ define i32 @test5a(i32 %A) {
|
|||||||
ret i32 %B
|
ret i32 %B
|
||||||
}
|
}
|
||||||
|
|
||||||
define <4 x i32> @test5a_splat_vector(<4 x i32> %A) {
|
|
||||||
; CHECK-LABEL: @test5a_splat_vector(
|
|
||||||
; CHECK: ret <4 x i32> undef
|
|
||||||
%B = shl <4 x i32> %A, <i32 32, i32 32, i32 32, i32 32> ;; shift all bits out
|
|
||||||
ret <4 x i32> %B
|
|
||||||
}
|
|
||||||
|
|
||||||
define <4 x i32> @test5a_non_splat_vector(<4 x i32> %A) {
|
|
||||||
; CHECK-LABEL: @test5a_non_splat_vector(
|
|
||||||
; CHECK-NOT: ret <4 x i32> undef
|
|
||||||
%B = shl <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
|
|
||||||
ret <4 x i32> %B
|
|
||||||
}
|
|
||||||
|
|
||||||
define i32 @test5b() {
|
define i32 @test5b() {
|
||||||
; CHECK-LABEL: @test5b(
|
; CHECK-LABEL: @test5b(
|
||||||
; CHECK: ret i32 -1
|
; CHECK: ret i32 -1
|
||||||
@ -815,32 +780,3 @@ bb11: ; preds = %bb8
|
|||||||
bb12: ; preds = %bb11, %bb8, %bb
|
bb12: ; preds = %bb11, %bb8, %bb
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
define i32 @test64(i32 %a) {
|
|
||||||
; CHECK-LABEL: @test64(
|
|
||||||
; CHECK-NEXT: ret i32 undef
|
|
||||||
%b = ashr i32 %a, 32 ; shift all bits out
|
|
||||||
ret i32 %b
|
|
||||||
}
|
|
||||||
|
|
||||||
define <4 x i32> @test64_splat_vector(<4 x i32> %a) {
|
|
||||||
; CHECK-LABEL: @test64_splat_vector
|
|
||||||
; CHECK-NEXT: ret <4 x i32> undef
|
|
||||||
%b = ashr <4 x i32> %a, <i32 32, i32 32, i32 32, i32 32> ; shift all bits out
|
|
||||||
ret <4 x i32> %b
|
|
||||||
}
|
|
||||||
|
|
||||||
define <4 x i32> @test64_non_splat_vector(<4 x i32> %a) {
|
|
||||||
; CHECK-LABEL: @test64_non_splat_vector
|
|
||||||
; CHECK-NOT: ret <4 x i32> undef
|
|
||||||
%b = ashr <4 x i32> %a, <i32 32, i32 0, i32 1, i32 2> ; shift all bits out
|
|
||||||
ret <4 x i32> %b
|
|
||||||
}
|
|
||||||
|
|
||||||
define <2 x i65> @test_65(<2 x i64> %t) {
|
|
||||||
; CHECK-LABEL: @test_65
|
|
||||||
%a = zext <2 x i64> %t to <2 x i65>
|
|
||||||
%sext = shl <2 x i65> %a, <i65 33, i65 33>
|
|
||||||
%b = ashr <2 x i65> %sext, <i65 33, i65 33>
|
|
||||||
ret <2 x i65> %b
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user