This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnswitch] Deny loop unswitch if its body contains volatile inline asm
AbandonedPublic

Authored by kovdan01 on Jan 14 2022, 4:57 AM.

Details

Summary

Volatile inline asm might contain convergent insructions.
Unswitching such loops breaks code correctness for targets like NVPTX.

Diff Detail

Event Timeline

kovdan01 created this revision.Jan 14 2022, 4:57 AM
kovdan01 requested review of this revision.Jan 14 2022, 4:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2022, 4:57 AM
fhahn added a comment.Jan 14 2022, 5:07 AM

If inline assembly calls can be convergent in general, should CallBase::isConvergent handle this? otherwise we might run into similar mis-compiles in other transforms.

If inline assembly calls can be convergent in general, should CallBase::isConvergent handle this? otherwise we might run into similar mis-compiles in other transforms.

I suppose that CallBase::isConvergent can’t handle this. Without the change, test with volatile inline asm fails (the unswitching is performed) – it indicates that marking inline asm as volatile does not set convergent attribute on corresponding CallBase.

nikic requested changes to this revision.Jan 14 2022, 5:52 AM
nikic added a subscriber: nikic.

The frontend is responsible for adding the convergent attribute to inline asm if necessary, see https://github.com/llvm/llvm-project/blob/e58e401b798845ebaf131528d286b39dadfda914/clang/lib/CodeGen/CGStmt.cpp#L2245-L2250.

This revision now requires changes to proceed.Jan 14 2022, 5:52 AM
kovdan01 abandoned this revision.EditedJan 15 2022, 2:50 AM

The frontend is responsible for adding the convergent attribute to inline asm if necessary, see https://github.com/llvm/llvm-project/blob/e58e401b798845ebaf131528d286b39dadfda914/clang/lib/CodeGen/CGStmt.cpp#L2245-L2250.

Thank you for your review! Didn't know that. Appropriate tests already exist (for example, clang/test/CodeGenCUDA/convergent.cu), so close this revision.