Manual-sync mirror of chromium.googlesource.com/external/github.com/llvm/llvm-project (bare monorepo, no subtree suffix)
Find a file
Victor Perez bdd8c64a2a
[mlir][arith] Fold trivial integer division and remainder (#212074)
Add value-preserving folds mirroring LLVM's InstructionSimplify for the
integer division and remainder ops:

```
divui/divsi/ceildivui/ceildivsi/floordivsi(0, x) -> 0
divui/divsi/ceildivui/ceildivsi/floordivsi(x, x) -> 1
remui/remsi(0, x) -> 0
remui/remsi(x, x) -> 0
```

The self and zero-dividend cases are valid refinements because division
or remainder by zero is undefined behaviour; no overflow flags are
required. The folds return a scalar or splat constant and bail out on
shaped types with a dynamic shape.

Folding `x / 0` and `x % 0` to poison is left as a TODO: it would make
the arith dialect depend on the ub dialect to materialize `ub.poison`.

LLVM performs the same simplifications: https://godbolt.org/z/dzTjYjs4e

Verified with Alive2:

| Fold | udiv | sdiv | urem | srem |
| :--- | :---: | :---: | :---: | :---: |
| `x / x -> 1`, `x % x -> 0` | [✓](https://alive2.llvm.org/ce/z/YjZCEA)
| [✓](https://alive2.llvm.org/ce/z/BSWQrm) |
[✓](https://alive2.llvm.org/ce/z/gx5sRH) |
[✓](https://alive2.llvm.org/ce/z/VUYkr4) |
| `0 / x -> 0`, `0 % x -> 0` | [✓](https://alive2.llvm.org/ce/z/keqeCZ)
| [✓](https://alive2.llvm.org/ce/z/jyf5wm) |
[✓](https://alive2.llvm.org/ce/z/fZa6ND) |
[✓](https://alive2.llvm.org/ce/z/fo6ss8) |

----

Code generated by Claude Code.

Signed-off-by: Víctor Pérez Carrasco <victor.pc.upm@gmail.com>
2026-07-26 16:25:34 +00:00
.ci [libc++] Rename pre-commit CI workflows (#211844) 2026-07-24 14:56:19 -04:00
.github workflows/libclang-abi-tests: Fix missing environment variable (#211959) 2026-07-25 22:25:08 -07:00
bolt [LoopInfo] Store blocks using Euler tour representation (#211485) 2026-07-25 01:57:01 +00:00
clang [clang][CFG] Fix compound assignment evaluation order (#212115) 2026-07-26 16:21:01 +01:00
clang-tools-extra [llvm][ADT] Mark llvm::IntrusiveRefCntPtr with the warn_unused attribute (#211795) 2026-07-26 13:58:39 +00:00
cmake Bump version to 24.0.0git (#209473) 2026-07-14 09:21:03 -04:00
compiler-rt [PGO][HIP] Support hipModuleLoad in offload PGO (#211875) 2026-07-25 09:50:07 -04:00
cross-project-tests cross-project-tests: Migrate amdgpu tests to use subarch triples (#210115) 2026-07-24 17:38:34 +02:00
flang [flang][cuda] Accept statement function in device code (#211957) 2026-07-25 01:07:01 +00:00
flang-rt [flang-rt][cuda] Keep device-context cleanup probe from leaking a last-error (#211910) 2026-07-24 21:23:58 +00:00
libc [libc][cpp::string] Allocate fewer temp strings in operator= and += (#210895) 2026-07-26 07:25:50 -07:00
libclc libclc: Fix signed 0 handling in sincospi (#211260) 2026-07-23 06:24:44 +02:00
libcxx [libc++][chrono] Implement LWG 4274: Allow chrono::hh_mm_ss to be constructed from unsigned durations (#209686) 2026-07-27 00:09:16 +08:00
libcxxabi [libc++abi][NFC] Remove some XFAILs which never trigger (#211241) 2026-07-26 16:19:32 +02:00
libsycl [libsycl][NFC] Move the cmake msvc DLL check (#193485) 2026-07-20 16:55:25 +02:00
libunwind [libunwind][PPC64] Fix unw_getcontext corrupting callee-saved VSX registers on LE (#198371) 2026-07-25 12:11:31 -07:00
lld [ELF] Retain .got for revertible no-PIC GOTPCRELX optimization (#212077) 2026-07-25 17:49:47 -07:00
lldb [lldb] Move GetVTableInfo to C++ language runtime (#207010) 2026-07-25 11:01:04 +02:00
llvm [llvm][ADT] Mark llvm::IntrusiveRefCntPtr with the warn_unused attribute (#211795) 2026-07-26 13:58:39 +00:00
llvm-libgcc [docs] Finish misc MyST migration (#210209) 2026-07-17 11:56:59 -07:00
mlir [mlir][arith] Fold trivial integer division and remainder (#212074) 2026-07-26 16:25:34 +00:00
offload [OFFLOAD][L0] Properly consume errors in program validation (#211799) 2026-07-24 16:49:57 +02:00
openmp FIX some OMPT tests that fail on RISC-V (#156914) 2026-07-24 11:24:36 +02:00
orc-rt [orc-rt] Add comment to clarify intended control flow. NFC. (#211454) 2026-07-23 13:25:32 +10:00
polly [SCEV] Use SCEVPtrToAddr instead of SCEVPtrToInt in SCEV. (#180244) 2026-07-24 20:20:48 +01:00
runtimes Remove debug leftovers (#211068) 2026-07-21 23:23:13 -07:00
third-party Fix a warning and an uninitialized variable in benchmark (#200927) 2026-06-02 13:49:06 -07:00
utils [Bazel] Fixes abd6e74 (#212081) 2026-07-26 09:20:05 +02:00
.clang-format
.clang-format-ignore [Docs] Update coding standard for TD files (#200848) 2026-06-01 21:35:58 +01:00
.clang-tidy Add default empty header filter regex to root .clang-tidy (#167386) 2025-11-11 01:36:25 +03:00
.git-blame-ignore-revs Add "Split clang/lib/CodeGen/CGBuiltin.cpp" to .git-blame-ignore-revs (#203419) 2026-06-12 12:03:28 +01:00
.gitattributes [libclang/python] Enable packaging clang python bindings (#125806) 2025-11-24 17:21:24 -08:00
.gitignore gitignore: Add emacs lock files (#205055) 2026-06-22 18:19:29 +02:00
.mailmap mailmap: Add entries for Peter Collingbourne. (#210526) 2026-07-18 11:02:06 -07:00
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.TXT
pyproject.toml [docs] Create utils/docs (#203962) 2026-06-24 15:12:48 -04:00
README.md [libc++] Rename pre-commit CI workflows (#211844) 2026-07-24 14:56:19 -04:00
SECURITY.md [SECURITY.md] add pointers to "what is a security issue" (#177372) 2026-01-22 17:19:09 -07:00

The LLVM Compiler Infrastructure

OpenSSF Scorecard OpenSSF Best Practices libc++

Welcome to the LLVM project!

This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.

The LLVM project has multiple components. The core of the project is itself called "LLVM". This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.

C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.

Other components include: the libc++ C++ standard library, the LLD linker, and more.

Getting the Source Code and Building LLVM

Consult the Getting Started with LLVM page for information on building and running LLVM.

For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.

Getting in touch

Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.

The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.