[llvm] [GlobalISel] Drop nuw/nsw/disjoint when widening a result with G_ANYEXT (PR #218558)
Chinmay Deshpande via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 12:00:03 PDT 2026
================
@@ -3006,6 +3006,11 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
// don't affect the result) and then truncate the result back to the
// original type.
Observer.changingInstr(MI);
+ // The G_ANYEXTs below leave the new high bits unconstrained, so no-wrap and
+ // disjoint claims proved at the narrow width no longer hold. Paths that
+ // widen with value-preserving G_ZEXT/G_SEXT keep their flags.
+ MI.clearFlags(MachineInstr::NoUWrap | MachineInstr::NoSWrap |
+ MachineInstr::Disjoint);
----------------
chinmaydd wrote:
I wonder if a cleaner fix is to do something like:
```
void LegalizerHelper::widenScalarSrc(MachineInstr &MI, LLT WideTy,
unsigned OpIdx, unsigned ExtOpcode) {
if (ExtOpcode == TargetOpcode::G_ANYEXT)
// clear flags
...
}
```
Also, this seems to be missing a dedicated MIR tests for opcodes such as `G_ADD`, `G_AND`, etc..
https://github.com/llvm/llvm-project/pull/218558
More information about the llvm-commits
mailing list