llvm.org GIT mirror llvm / 2b0002b
Workaround MSVC 32-bit miscompile of getCondCodeAction. Use 32-bit types for the array instead of 64. This should generally be better anyway. In optimized + assert builds, I saw a failure when a cond code / type combination that is never set was loading a non-zero value and hitting the != Promote assert. It turns out when loading the 64-bit value to do the shift, the assembly loads the 2 32-bit halves from non-consecutive addresses. The address the second half of the loaded uint64_t doesn't include the offset of the array in the struct. Instead of being offset + 4, it's just + 4. I'm not entirely sure why this wasn't observed before. setCondCodeAction isn't heavily used by the in-tree targets, and not with the higher valued vector SimpleValueTypes. Only PPC is using one of the > 32 valued types, and that is probably never used by anyone on a 32-bit MSVC compiled host. I ran into this when upgrading LLVM versions, so I guess the value loaded from the nonsense address happened to work out before. No test since I'm not really sure if / how it can be reproduced with the current in tree targets, and it's not supposed to change anything. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193650 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 6 years ago
1 changed file(s) with 13 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
519519 LegalizeAction
520520 getCondCodeAction(ISD::CondCode CC, MVT VT) const {
521521 assert((unsigned)CC < array_lengthof(CondCodeActions) &&
522 (unsigned)VT.SimpleTy < sizeof(CondCodeActions[0])*4 &&
522 ((unsigned)VT.SimpleTy >> 4) < array_lengthof(CondCodeActions[0]) &&
523523 "Table isn't big enough!");
524 /// The lower 5 bits of the SimpleTy index into Nth 2bit set from the 64bit
525 /// value and the upper 27 bits index into the second dimension of the
526 /// array to select what 64bit value to use.
527 LegalizeAction Action = (LegalizeAction)
528 ((CondCodeActions[CC][VT.SimpleTy >> 5] >> (2*(VT.SimpleTy & 0x1F))) & 3);
524 // See setCondCodeAction for how this is encoded.
525 uint32_t Shift = 2 * (VT.SimpleTy & 0xF);
526 uint32_t Value = CondCodeActions[CC][VT.SimpleTy >> 4];
527 LegalizeAction Action = (LegalizeAction) ((Value >> Shift) & 0x3);
529528 assert(Action != Promote && "Can't promote condition code!");
530529 return Action;
531530 }
10191018 assert(VT < MVT::LAST_VALUETYPE &&
10201019 (unsigned)CC < array_lengthof(CondCodeActions) &&
10211020 "Table isn't big enough!");
1022 /// The lower 5 bits of the SimpleTy index into Nth 2bit set from the 64bit
1023 /// value and the upper 27 bits index into the second dimension of the
1024 /// array to select what 64bit value to use.
1025 CondCodeActions[(unsigned)CC][VT.SimpleTy >> 5]
1026 &= ~(uint64_t(3UL) << (VT.SimpleTy & 0x1F)*2);
1027 CondCodeActions[(unsigned)CC][VT.SimpleTy >> 5]
1028 |= (uint64_t)Action << (VT.SimpleTy & 0x1F)*2;
1021 /// The lower 5 bits of the SimpleTy index into Nth 2bit set from the 32-bit
1022 /// value and the upper 27 bits index into the second dimension of the array
1023 /// to select what 32-bit value to use.
1024 uint32_t Shift = 2 * (VT.SimpleTy & 0xF);
1025 CondCodeActions[CC][VT.SimpleTy >> 4] &= ~((uint32_t)0x3 << Shift);
1026 CondCodeActions[CC][VT.SimpleTy >> 4] |= (uint32_t)Action << Shift;
10291027 }
10301028
10311029 /// If Opc/OrigVT is specified as being promoted, the promotion code defaults
14471445 ///
14481446 /// Because each CC action takes up 2 bits, we need to have the array size be
14491447 /// large enough to fit all of the value types. This can be done by dividing
1450 /// the MVT::LAST_VALUETYPE by 32 and adding one.
1451 uint64_t CondCodeActions[ISD::SETCC_INVALID][(MVT::LAST_VALUETYPE / 32) + 1];
1448 /// the MVT::LAST_VALUETYPE by 16 and adding one.
1449 uint32_t CondCodeActions[ISD::SETCC_INVALID][(MVT::LAST_VALUETYPE + 15) / 16];
14521450
14531451 ValueTypeActionImpl ValueTypeActions;
14541452