@@ -218,6 +218,19 @@ static bool matchSelectWithOptionalNotCond(Value *V, Value *&Cond, Value *&A,
218
218
return true ;
219
219
}
220
220
221
+ static unsigned hashCallInst (CallInst *CI) {
222
+ // Don't CSE convergent calls in different basic blocks, because they
223
+ // implicitly depend on the set of threads that is currently executing.
224
+ if (CI->isConvergent ()) {
225
+ return hash_combine (
226
+ CI->getOpcode (), CI->getParent (),
227
+ hash_combine_range (CI->value_op_begin (), CI->value_op_end ()));
228
+ }
229
+ return hash_combine (
230
+ CI->getOpcode (),
231
+ hash_combine_range (CI->value_op_begin (), CI->value_op_end ()));
232
+ }
233
+
221
234
static unsigned getHashValueImpl (SimpleValue Val) {
222
235
Instruction *Inst = Val.Inst ;
223
236
// Hash in all of the operands as pointers.
@@ -320,11 +333,8 @@ static unsigned getHashValueImpl(SimpleValue Val) {
320
333
321
334
// Don't CSE convergent calls in different basic blocks, because they
322
335
// implicitly depend on the set of threads that is currently executing.
323
- if (CallInst *CI = dyn_cast<CallInst>(Inst); CI && CI->isConvergent ()) {
324
- return hash_combine (
325
- Inst->getOpcode (), Inst->getParent (),
326
- hash_combine_range (Inst->value_op_begin (), Inst->value_op_end ()));
327
- }
336
+ if (CallInst *CI = dyn_cast<CallInst>(Inst))
337
+ return hashCallInst (CI);
328
338
329
339
// Mix in the opcode.
330
340
return hash_combine (
@@ -524,15 +534,21 @@ unsigned DenseMapInfo<CallValue>::getHashValue(CallValue Val) {
524
534
Instruction *Inst = Val.Inst ;
525
535
526
536
// Hash all of the operands as pointers and mix in the opcode.
527
- return hash_combine (
528
- Inst->getOpcode (),
529
- hash_combine_range (Inst->value_op_begin (), Inst->value_op_end ()));
537
+ return hashCallInst (cast<CallInst>(Inst));
530
538
}
531
539
532
540
bool DenseMapInfo<CallValue>::isEqual(CallValue LHS, CallValue RHS) {
533
- Instruction *LHSI = LHS.Inst , *RHSI = RHS.Inst ;
534
541
if (LHS.isSentinel () || RHS.isSentinel ())
535
- return LHSI == RHSI;
542
+ return LHS.Inst == RHS.Inst ;
543
+
544
+ CallInst *LHSI = cast<CallInst>(LHS.Inst );
545
+ CallInst *RHSI = cast<CallInst>(RHS.Inst );
546
+
547
+ // Convergent calls implicitly depend on the set of threads that is
548
+ // currently executing, so conservatively return false if they are in
549
+ // different basic blocks.
550
+ if (LHSI->isConvergent () && LHSI->getParent () != RHSI->getParent ())
551
+ return false ;
536
552
537
553
return LHSI->isIdenticalTo (RHSI);
538
554
}
0 commit comments