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

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 13 18:07:26 PDT 2022


Allen marked 2 inline comments as done.
Allen added inline comments.


================
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
>it doesn't have scvtf, also see the range (-100, 100] in https://godbolt.org/z/jMhxfnbs9




================
Comment at: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp:694
+      CastInst::CastOps Opcode = CI->getOpcode();
+      if (Opcode != CastInst::FPToSI && Opcode != CastInst::FPToUI)
+        continue;
----------------
nikic wrote:
> Allen wrote:
> > 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
> > >it doesn't have scvtf, also see the range (-100, 100] in https://godbolt.org/z/jMhxfnbs9
> > 
> > 
> 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.
Done, thanks.


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

https://reviews.llvm.org/D129358



More information about the llvm-commits mailing list