aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-13 17:38:28 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-02-13 17:38:28 -0800
commita56ee7bb7045c096b1903245c1862220c11c3d30 (patch)
tree1eded5a3a2f33bdeaf2e9de9676be59194b38470 /lib/Transforms
parent14141ab8c1b9239e114f04fcbaca823bb9766c92 (diff)
don't do 32-bit shifts on 32-bit values, as it is undefined behavior
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/NaCl/ExpandI64.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Transforms/NaCl/ExpandI64.cpp b/lib/Transforms/NaCl/ExpandI64.cpp
index aabcb69657..ae3b67e6e7 100644
--- a/lib/Transforms/NaCl/ExpandI64.cpp
+++ b/lib/Transforms/NaCl/ExpandI64.cpp
@@ -493,8 +493,9 @@ bool ExpandI64::splitInst(Instruction *I) {
assert(I->getOpcode() == Instruction::LShr || I->getOpcode() == Instruction::AShr || I->getOpcode() == Instruction::Shl);
ConstantInt *CI = cast<ConstantInt>(I->getOperand(1));
unsigned Shifts = CI->getZExtValue();
- Constant *Frac = ConstantInt::get(i32, Shifts % 32);
- Constant *Comp = ConstantInt::get(i32, 32 - (Shifts % 32));
+ unsigned Fraction = Shifts % 32;
+ Constant *Frac = ConstantInt::get(i32, Fraction);
+ Constant *Comp = ConstantInt::get(i32, 32 - Fraction);
Instruction::BinaryOps Opcode, Reverse;
unsigned ShiftChunks, Dir;
Value *TopFiller = Zero;
@@ -530,11 +531,19 @@ bool ExpandI64::splitInst(Instruction *I) {
// shifted the fractional amount
if (Frac != Zero && L != Zero) {
- L = CopyDebug(BinaryOperator::Create(Opcode, L, Frac, "", I), I);
+ if (Fraction == 32) {
+ L = Zero;
+ } else {
+ L = CopyDebug(BinaryOperator::Create(Opcode, L, Frac, "", I), I);
+ }
}
// shifted the complement-fractional amount to the other side
if (Comp != Zero && H != Zero) {
- H = CopyDebug(BinaryOperator::Create(Reverse, H, Comp, "", I), I);
+ if (Fraction == 0) {
+ H = TopFiller;
+ } else {
+ H = CopyDebug(BinaryOperator::Create(Reverse, H, Comp, "", I), I);
+ }
}
// Or the parts together. Since we may have zero, try to fold it away.