Need help reducing this testcase with bugpoint

Hi:
I’ve currently encountered a bug and has reduced the test case to a single translation unit.

I could trigger the bug as demonstrated below:

clang caller.ll -lc++ -lCryptoPP -L. -o cryptest.exe -O1
./cryptest.exe v 12

which miscompiles:

Using seed: 1648185804

3-WAY validation suite running...

passed:  Algorithm key lengths
passed   000000000000000000000000   000000010000000100000001   4059C76E83AE9DC4AD21ECF7
FAILED   000000060000000500000004   8B0B0772EB68EA830A2B3365   D2F05B5ED6144138CAB920CD
FAILED   DEF01234456789ABBCDEF012   DC743C8429B373909B0E4FE2   0AA55DBB9CDDDB6D7CDB76B2
FAILED   D2F05B5ED6144138CAB920CD   42C74CFAA1D9F31E2A57FBD3   478EA8716B13F17C15B155ED

Seed used was 1648185804
Test started at Fri Mar 25 13:23:24 2022
Test ended at Fri Mar 25 13:23:24 2022

However the program is fine if compiled with O0:

➜  CryptoPP ./cryptest.exe v 12
Using seed: 1648185844

3-WAY validation suite running...

passed:  Algorithm key lengths
passed   000000000000000000000000   000000010000000100000001   4059C76E83AE9DC4AD21ECF7
passed   000000060000000500000004   000000030000000200000001   D2F05B5ED6144138CAB920CD
passed   DEF01234456789ABBCDEF012   234567899ABCDEF001234567   0AA55DBB9CDDDB6D7CDB76B2
passed   D2F05B5ED6144138CAB920CD   4059C76E83AE9DC4AD21ECF7   478EA8716B13F17C15B155ED

Seed used was 1648185844
Test started at Fri Mar 25 13:24:04 2022
Test ended at Fri Mar 25 13:24:04 2022

Trying to reduce with the following command:

bugpoint --compile-custom --compile-command="clang -lc++ -L. -lCryptoPP" -verbose-errors=true caller.ll --args "v"

however reducing failed due to linkage error, because bugpoint has deleted some of the functions in caller.ll, and adding –disable-dce -disable-simplifycfg doesn’t help

bugpoint is not great at reducing mis-compiles like this. You may want to try using https://llvm.org/docs/OptBisect.html instead.

If you did want to use bugpoint, you would need to write a script like this:

#!/bin/bash
set -e
clang $1 -lc++ -lCryptoPP -L. -o cryptest.exe -O1
if ./cryptest.exe v 12 | grep 'FAILED   000000060000000500000004   8B0B0772EB68EA830A2B3365   D2F05B5ED6144138CAB920CD'; then
  exit 1
else
  exit 0
fi

But I doubt this will help reduce the input much.

do you mind posting the IR file that gets miscompiled plus whatever other code is needed to repro this? (apologies if you did and I missed it, I’m still getting used to discourse)

Hi:
Thanks for the interest, it seems this is not technically an LLVM bug, but rather UB introduced by our downstream transform passes, that later triggers LLVM bug. You can see the follow-up here: EarlyCSE results in miscompiled binary · Issue #54545 · llvm/llvm-project · GitHub