[SimplifyCFG][OpaquePtr] Check store type when merging conditional store
authorArthur Eubanks <aeubanks@google.com>
Sun, 20 Feb 2022 19:29:54 +0000 (11:29 -0800)
committerArthur Eubanks <aeubanks@google.com>
Sun, 20 Feb 2022 19:29:54 +0000 (11:29 -0800)
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/opaque-ptr.ll

index dbf22ab..88a7e12 100644 (file)
@@ -3732,7 +3732,9 @@ static bool mergeConditionalStoreToAddress(
     return false;
 
   // Now check the stores are compatible.
-  if (!QStore->isUnordered() || !PStore->isUnordered())
+  if (!QStore->isUnordered() || !PStore->isUnordered() ||
+      PStore->getValueOperand()->getType() !=
+          QStore->getValueOperand()->getType())
     return false;
 
   // Check that sinking the store won't cause program behavior changes. Sinking
index 909346f..d63fdd7 100644 (file)
@@ -44,3 +44,36 @@ join:
   %phi = phi ptr [ %gep1, %if ], [ %gep2, %else]
   ret ptr %phi
 }
+
+define void @test_cond_store_merge(i1 %arg, i1 %arg2, ptr %p) {
+; CHECK-LABEL: @test_cond_store_merge(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    br i1 [[ARG:%.*]], label [[BB2:%.*]], label [[BB3:%.*]]
+; CHECK:       bb2:
+; CHECK-NEXT:    store i64 0, ptr [[P:%.*]], align 32
+; CHECK-NEXT:    br label [[BB3]]
+; CHECK:       bb3:
+; CHECK-NEXT:    br i1 [[ARG2:%.*]], label [[BB4:%.*]], label [[BB5:%.*]]
+; CHECK:       bb4:
+; CHECK-NEXT:    store double 0.000000e+00, ptr [[P]], align 32
+; CHECK-NEXT:    br label [[BB5]]
+; CHECK:       bb5:
+; CHECK-NEXT:    ret void
+;
+bb:
+  br i1 %arg, label %bb2, label %bb3
+
+bb2:                                              ; preds = %bb
+  store i64 0, ptr %p, align 32
+  br label %bb3
+
+bb3:                                              ; preds = %bb2, %bb
+  br i1 %arg2, label %bb4, label %bb5
+
+bb4:                                              ; preds = %bb3
+  store double 0.000000e+00, ptr %p, align 32
+  br label %bb5
+
+bb5:                                              ; preds = %bb4, %bb3
+  ret void
+}