[PATCH] When canonicalizing gep indices, prefer zext when possible
David Majnemer
david.majnemer at gmail.com
Thu Feb 12 10:51:52 PST 2015
================
Comment at: lib/Transforms/InstCombine/InstCombineCasts.cpp:1067-1074
@@ -1066,1 +1066,10 @@
+ // If we know that the value being extended is positive, we can use a zext
+ // instead.
+ bool KnownZero, KnownOne;
+ ComputeSignBit(Src, KnownZero, KnownOne, 0, &CI);
+ if (KnownZero) {
+ Value *ZExt = Builder->CreateZExt(Src, DestTy);
+ return ReplaceInstUsesWith(CI, ZExt);
+ }
+
----------------
This looks like it can be a separate change.
================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:1326-1331
@@ -1325,5 +1325,8 @@
// If we are using a wider index than needed for this platform, shrink
- // it to what we need. If narrower, sign-extend it to what we need.
+ // it to what we need. If narrower, sign-extend it to what we need
+ // (unless we can tell it's positive, in which case zero-extend.)
// This explicit cast can make subsequent optimizations more obvious.
- *I = Builder->CreateIntCast(*I, IntPtrTy, true);
+ bool KnownZero, KnownOne;
+ ComputeSignBit(*I, KnownZero, KnownOne, 0, &GEP);
+ *I = Builder->CreateIntCast(*I, IntPtrTy, !KnownZero);
MadeChange = true;
----------------
Isn't this change redundant with the one in InstCombineCasts? It would be nice to have this logic in one place.
http://reviews.llvm.org/D7255
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list