Test case:
https://llvm.godbolt.org/z/6W61azGsn
define i1 @pr4917_4(i32 %x) {
entry:
%r = zext i32 %x to i64
%0 = trunc i64 %r to i34
%new0 = mul i34 %0, %0
;3363831808 * 3363831808 % 2^34 == 0, thus new0 is 0
%last = zext i34 %new0 to i64
%overflow = icmp ule i64 %last, 4294967295 ;FFFFFFFF
ret i1 %overflow
}
This test case is a mutated version of https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/InstCombine/overflow-mul.ll#L77
Conisder input x=3363831808, the original function returns 1 baceuse 3363831808^2 % 2^34 ==0. However, the optmized function returns 0.
https://alive2.llvm.org/ce/z/5nNo_z
The ouput is verified by lli with following test driver:
#include <iostream>
bool f(unsigned int x);
int main(){
unsigned int a=3363831808;
std::cout<<f(a)<<"\n";
}
So the miscompile does exist.
@regehr @nunoplopes
Test case:
https://llvm.godbolt.org/z/6W61azGsn
This test case is a mutated version of https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/InstCombine/overflow-mul.ll#L77
Conisder input
x=3363831808, the original function returns 1 baceuse3363831808^2 % 2^34 ==0. However, the optmized function returns 0.https://alive2.llvm.org/ce/z/5nNo_z
The ouput is verified by
lliwith following test driver:So the miscompile does exist.
@regehr @nunoplopes