[PATCH] D129358: [IndVars] Eliminate redundant type cast between unsigned integer and float

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 13 05:41:58 PDT 2022


nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM

The next step here could be to also support uitofp.



================
Comment at: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp:694
+      CastInst::CastOps Opcode = CI->getOpcode();
+      if (Opcode != CastInst::FPToSI && Opcode != CastInst::FPToUI)
+        continue;
----------------
Allen wrote:
> nikic wrote:
> > For fptoui, shouldn't we also check that it's non-negative? Wouldn't your current code optimize an IV that does `-100` to `100` for example?
> thanks @nikic very much, and I verified that the gcc also transform with negative value, see detail in https://godbolt.org/z/1hxebdYfr
Ah yes, it is fine because FPToUI with negative value results in poison anyway. It would probably still be valuable to add a test with negative IV.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129358/new/

https://reviews.llvm.org/D129358



More information about the llvm-commits mailing list