[llvm] 2de368f - [InstCombine] FoldShiftByConstant - merge equivalent types. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 12 10:19:07 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-12T18:17:19+01:00
New Revision: 2de368f6a780f4cdbaf9cf8a4f803272f5de5938
URL: https://github.com/llvm/llvm-project/commit/2de368f6a780f4cdbaf9cf8a4f803272f5de5938
DIFF: https://github.com/llvm/llvm-project/commit/2de368f6a780f4cdbaf9cf8a4f803272f5de5938.diff
LOG: [InstCombine] FoldShiftByConstant - merge equivalent types. NFCI.
Consistently use the original shift instruction's Type/BitWidth instead of the operands, casted values etc.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 43b700572826..3a4f64ef341b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -676,8 +676,8 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
// See if we can simplify any instructions used by the instruction whose sole
// purpose is to compute bits we don't care about.
- unsigned TypeBits = Op0->getType()->getScalarSizeInBits();
-
+ Type *Ty = I.getType();
+ unsigned TypeBits = Ty->getScalarSizeInBits();
assert(!Op1C->uge(TypeBits) &&
"Shift over the type width should have been removed already");
@@ -707,9 +707,8 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
// clear the top bits as needed. This 'and' will usually be zapped by
// other xforms later if dead.
unsigned SrcSize = SrcTy->getScalarSizeInBits();
- unsigned DstSize = TI->getType()->getScalarSizeInBits();
Constant *MaskV =
- ConstantInt::get(SrcTy, APInt::getLowBitsSet(SrcSize, DstSize));
+ ConstantInt::get(SrcTy, APInt::getLowBitsSet(SrcSize, TypeBits));
// The mask we constructed says what the trunc would do if occurring
// between the shifts. We want to know the effect *after* the second
@@ -719,7 +718,7 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
// shift1 & 0x00FF
Value *And = Builder.CreateAnd(NSh, MaskV, TI->getName());
// Return the value truncated to the interesting size.
- return new TruncInst(And, I.getType());
+ return new TruncInst(And, Ty);
}
}
More information about the llvm-commits
mailing list