[PATCH] D123629: [InstCombine] Fold memrchr calls with a constant character.

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 13 03:47:51 PDT 2022


nikic requested changes to this revision.
nikic added inline comments.
This revision now requires changes to proceed.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:914
+      // to null regardless of Size.
+      return Constant::getNullValue(CI->getType());
+
----------------
Use NullPtr?


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:922
+                                   "memrchr.ptr_plus");
+      return B.CreateSelect(Cmp, NullPtr, SrcPlus, "memrchr.sel");
+    }
----------------
I don't think this is correct. Consider an unknown size and a string with two occurrences of C in it. Now assume that at runtime, the size is chosen to lie between the two occurrences of C. I believe your implementation will return null for that case, while it should return the first occurrence.


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

https://reviews.llvm.org/D123629



More information about the llvm-commits mailing list