$ cat >bad.ll <<EOL define i32 @src(i32 %x1, i32 %x2) { %x14 = add i32 %x1, %x2 %x6 = icmp ugt i32 %x14, %x2 %x9 = select i1 %x6, i32 %x14, i32 -1 ret i32 %x9 } EOL $ opt bad.ll --instcombine -S ; ModuleID = 'bad.ll' source_filename = "bad.ll" define i32 @src(i32 %x1, i32 %x2) { %1 = call i32 @llvm.uadd.sat.i32(i32 %x2, i32 %x1) ret i32 %1 } ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn declare i32 @llvm.uadd.sat.i32(i32, i32) #0 attributes #0 = { nofree nosync nounwind readnone speculatable willreturn } Alive output: ---------------------------------------- define i32 @src(i32 %x1, i32 %x2) { %0: %x14 = add i32 %x1, %x2 %x6 = icmp ugt i32 %x14, %x2 %x9 = select i1 %x6, i32 %x14, i32 4294967295 ret i32 %x9 } => define i32 @tgt(i32 %x1, i32 %x2) { %0: %1 = uadd_sat i32 %x2, %x1 ret i32 %1 } Transformation doesn't verify! ERROR: Value mismatch Example: i32 %x1 = #x00000000 (0) i32 %x2 = #x04000000 (67108864) Source: i32 %x14 = #x04000000 (67108864) i1 %x6 = #x0 (0) i32 %x9 = #xffffffff (4294967295, -1) Target: i32 %1 = #x04000000 (67108864) Source value: #xffffffff (4294967295, -1) Target value: #x04000000 (67108864)
Thanks for the report. I put a potential fix up as https://reviews.llvm.org/D92717.
I guess this bisects down to https://reviews.llvm.org/rGbf21f0d489fb461a8eeb4d6342d28ed2c6e4048d / https://reviews.llvm.org/D69244
Fixed by f16320b90b8381f2e3aac1ec17f39eff06f09ea0, e6f2a79d7aa01f8dd7f0194f97a50b480e8ede71. This should probably go into stable branch.
Merged: 8511a8df838f