[PATCH] [SeparateConstOffsetFromGEP] Fix an illegitimate optimization on zext
Jingyue Wu
jingyue at google.com
Sat Jun 7 10:47:56 PDT 2014
Hi eliben, meheff,
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
http://reviews.llvm.org/D4055
Files:
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
Index: lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
===================================================================
--- lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -297,9 +297,9 @@
// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4055.10206.patch
Type: text/x-patch
Size: 869 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140607/73db7081/attachment.bin>
More information about the llvm-commits
mailing list