Issue 244328
Summary [RISCV] RV32IM can choose an out-of-range shift when expanding a multiply by a constant
Labels new issue
Assignees
Reporter Kuree
    The RISC-V backend miscompiles the following C function on RV32IM at -O2.
 
```C
typedef unsigned long long u64;
void scale_pair(u64 x, u64 y, u64 *out) {
    out[0] = x * 0x180000000ULL;
 out[1] = y * 0x180000000ULL;
}
```

Here is a minimized LLVM input:

```LLVM
define i32 @f(i32 %x) {
  %k = bitcast i32 -536870912 to i32
  %r = mul i32 %x, %k
  ret i32 %r
}
```

`bitcast` is used to model an opaque constant value produced via`ConstantHoisting`.

Current LLVM producces

```ASM
f:                             
 ret
```

The bug started in 19.1.0. See godbolt here: https://godbolt.org/z/ahas9j7K8

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to