[PATCH] D131731: [InstCombine] Remove assumptions about int having 32 bits

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 11 15:25:18 PDT 2022


msebor created this revision.
msebor added reviewers: nikic, uabelho, bjope.
Herald added subscribers: pengfei, hiraditya, dylanmckay.
Herald added a project: All.
msebor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The patch submitted in D129915 <https://reviews.llvm.org/D129915> and subsequently committed in rG0dcfe7aa35cd <https://reviews.llvm.org/rG0dcfe7aa35cd4f6dbeb739fcd05f93aa39394f0e> exposes a number of assumptions in `SimplifyLibcalls.cpp` about `int` having 32 bits.  Prior to the change the assumptions, although strictly unsafe, were benign even on 16-bit targets because the validation in `TargetLibraryInfoImpl::isValidProtoForLibFunc` enforced the corresponding restriction.  The change has corrected the function to consider valid on 16-bit targets those functions in whose declarations the `int` return type or argument corresponds to `i16`, but it did not update the corresponding call handlers in `SimplifyLibcalls.cpp`.  The end result is that some valid C code that compiled successfully before the change (albeit with suboptimal output) now causes an abort in the handler when targeting 16-bit environments (AVR or MSP430 in tree).

As a follow-up to D129915 <https://reviews.llvm.org/D129915>, this change removes these 32-bit assumptions to let the same code compile successfully even for 16-bit targets, and to also enable the same optimizing transformations for those targets as for 32-bit ones.

I've tested this patch on x86_64-linux.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131731

Files:
  llvm/lib/Transforms/Utils/BuildLibCalls.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/ffs-i16.ll
  llvm/test/Transforms/InstCombine/fls-i16.ll
  llvm/test/Transforms/InstCombine/isascii-i16.ll
  llvm/test/Transforms/InstCombine/isdigit-i16.ll
  llvm/test/Transforms/InstCombine/printf-i16.ll
  llvm/test/Transforms/InstCombine/puts-i16.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131731.451978.patch
Type: text/x-patch
Size: 18358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220811/c0c56caf/attachment.bin>


More information about the llvm-commits mailing list