diff options
author | Jingyue Wu <jingyue@google.com> | 2014-06-08 20:19:38 +0000 |
---|---|---|
committer | Jingyue Wu <jingyue@google.com> | 2014-06-08 20:19:38 +0000 |
commit | 01ceeb190d34231bbf2becb33ad1c809034f2bb0 (patch) | |
tree | 411b4404b79ba2e8b711b953d124230b226203b6 /llvm/lib | |
parent | 48a5abeec0614f4fd26ddb26e201d8c70d791ae3 (diff) | |
download | bcm5719-llvm-01ceeb190d34231bbf2becb33ad1c809034f2bb0.tar.gz bcm5719-llvm-01ceeb190d34231bbf2becb33ad1c809034f2bb0.zip |
[SeparateConstOffsetFromGEP] Fix an illegitimate optimization on zext
zext(a + b) != zext(a) + zext(b) even if a + b >= 0 && b >= 0.
e.g., a = i4 0b1111, b = i4 0b0001
zext a + b to i8 = zext 0b0000 to i8 = 0b00000000
(zext a to i8) + (zext b to i8) = 0b00001111 + 0b00000001 = 0b00010000
llvm-svn: 210439
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp index 3f84ffde946..7c65351ad15 100644 --- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp +++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp @@ -321,9 +321,9 @@ bool ConstantOffsetExtractor::CanTraceInto(bool SignExtended, // 1 | 0 | sext(BO) == sext(A) op sext(B) // 1 | 1 | zext(sext(BO)) == // | | zext(sext(A)) op zext(sext(B)) - if (BO->getOpcode() == Instruction::Add && NonNegative) { + if (BO->getOpcode() == Instruction::Add && !ZeroExtended && NonNegative) { // If a + b >= 0 and (a >= 0 or b >= 0), then - // s/zext(a + b) = s/zext(a) + s/zext(b) + // sext(a + b) = sext(a) + sext(b) // even if the addition is not marked nsw. // // Leveraging this invarient, we can trace into an sext'ed inbound GEP |