-
Notifications
You must be signed in to change notification settings - Fork 15.7k
Open
Labels
Description
Tested on x64 clang trunk
int foo_xor() {
int i;
int j;
return i ^ j;
}During optimization this reaches xor undef, undef
xor undef, undef then "optimizes" to 0
This is special cased to allow a ^ a to always be 0:
llvm-project/llvm/lib/IR/ConstantFold.cpp
Lines 628 to 632 in 4015545
| case Instruction::Xor: | |
| if (isa<UndefValue>(C1) && isa<UndefValue>(C2)) | |
| // Handle undef ^ undef -> 0 special case. This is a common | |
| // idiom (misuse). | |
| return Constant::getNullValue(C1->getType()); |
I am aware this is UB so the behaviour doesn't necessarily matter but it feels unreasonable that the 2 "different" undef's here xor to 0 and we inject a concrete 0 that the optimizer has to work around
Not sure there is a way in llvm's internals to specify that 2 undef values are different (e.g. if you had a ^ a are both undefs the same pointer?) so it may not be worth investigating but I thought I would raise